call_examplees
by upigilam
JavaScript
// example1
// borrowing array functions to non array object
let argsToArray = function () {
console.log("passed in arguments :: ", arguments);
// [].slice.call will convert non array in to array and it borrows array functions
console.log(" array arguments :: ", [].slice.call(arguments))
}
argsToArray(1,2,3);
// example2 : using call in function constructor
let v1 = function (x) {
this.x = x
}
let v2 = function(x, y){
v1.call(this, x);
this.y = y;
}
let hh = new v2(4, false);
console.log(hh);