You want to map values of an array to function parameters in ES5.
apply()
methodGiven: a function that takes different parameters and an array containing concrete arguments.
function add(x, y, z) {
return x + y + z;
}
var parameters = [2, 3, 4];
You want to define a static property inside a “class”.
Create a “class”.
class SomeClass {
constructor(property) {
this.property = property;
}
}
You want to define a static method inside a “class”.
static
keywordCreate a “class”.
class SomeClass {
constructor(property) {
this.property = property;
}
}
You want to apply inheritance using the class syntax introduced in ES2015.
extends
keywordsuper
keywordDefine a “class”. Optionally define some properties, getter and setters.
'use strict';
class Animal {
constructor(color) {
this._color = color;
}
get color() {
return this._color;
}
set color(color) {
this._color = color;
}
}
You want to create getters and setters for a class in ES2015.
get
and set
keywordsCreate a class with some properties.
class Person {
constructor(firstName, lastName) {
this._firstName = firstName;
this._lastName = lastName;
}
}