cachaito
3/10/2016 - 9:22 AM

Consturctor functions behind

// When we do this:
function Foo() {
  this.kind = 'foo';
}

var foo = new Foo();
foo.kind; //=> ‘foo’

// Behind the scenes it is like doing something like this:
function Foo() {
  // this is not valid, just for illustration
  var this = {};                  // Step 1
  this.__proto__ = Foo.prototype; // Step 2
  this.kind = 'foo';              // Step 3
  return this;                    // Step 4
}