Friday, July 29, 2016

Javascript - regular function call vs using new

function test(){
  this.a = 1;
  return a;
}

var a = test(); //a equals 1, this context in test will be window
var b = new test(); //b equals "test {a: 1}", this context is the function's context


No comments:

Post a Comment