I am reading YDKJS this and prototypes and here is a code snippet:
function foo(something){
console.log(this.a,something); //display the two numbers you got, one is this.a which is 2,
//second is an argument that is currently vacant and waiting for input
return this.a+something; //add this 2 numbers up
}
var obj={a:2};//set the value of a
var bar=function(){return foo.apply(obj,arguments);}; //?
var b=bar(3);
console.log(b);
I understand that in this snippet, they wrapped a bar
variable outside of the function call, just to create this so called hard binding and hence prevent this.a’s value changes to global variable.
What I dont understand is return foo.apply(obj,arguments);
I dont understand the syntax of it. could someone explain it to me what does it do?