Revision - Binding Loss

by andfinally

JavaScript

/*
 When you access a method via a reference, it loses its binding to its parent object.
*/

var User = {
  count: 1,

  getCount: function() {
    return this.count;
  }
};

console.log(User.getCount()); // 1

var func = User.getCount;
console.log(func()); // undefined