You want to use pseudoclassical inheritance, i.e., create a “class” as “subclass” of another “class”.
prototype
propertycall()
methodDefine a function intended to be a constructor function (this will be the “superclass”).
function Animal(color) {
this._color = color;
}
You want to convert the array-like object arguments
to a real array.
Array
prototypeslice()
methodcall()
methodGiven: a function that takes different parameters and accesses them via the arguments
object.
function printAllArguments() {
let values = arguments;
for(let i=0; i<values.length; i++) {
console.log(values[i]);
}
}
printAllArguments(2, 3, 4);
You want to emulate block level scope in ES5 to prevent naming conflicts.
Given: some code that you want to put in a block.
var aVariable = 2345;
// Block should start here
var aVariable = 4711;
console.log(aVariable); // should print 4711
// Block should end here
console.log(aVariable); // should print 2345, but prints 411