ES6 class super() with variadic arguments

javascript ecmascript-6 subclass

6331 просмотра

1 ответ

815 Репутация автора

In ES6, is there a way to call a parent constructor passing through variadic arguments, a la foo.apply(this, arguments)? I've looked for an answer, and the only instances I see are either calling super() (no arguments) or calling super(x, y) (with specific arguments). super.apply(this, arguments) doesn't appear to work.

Автор: Turner Hayes Источник Размещён: 18.07.2016 10:55

Ответы (1)

46 плюса

199645 Репутация автора


The pattern I find convenient and follow is

constructor(...args) {

In case you have and use named arguments you could do this instead:

constructor(a, b, c) {


Автор: zerkms Размещён: 18.07.2016 10:57
Вопросы из категории :