Skip to content

Instantly share code, notes, and snippets.

@alsotang
Created September 18, 2012 19:55
Show Gist options
  • Save alsotang/3745456 to your computer and use it in GitHub Desktop.
Save alsotang/3745456 to your computer and use it in GitHub Desktop.
js bind的一个简单示例
var obj1 = {
name: 'alsotang',
method: function() {
console.log(this.name);
}
};
var obj2 = {
name: 'freewind'
};
obj1.method(); // => 'alsotang'
var func1 = obj1.method;
func1(); // => 'undefined'
var func2 = obj1.method.bind(obj2);
func2(); // => 'freewind'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment