Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
链式调用
function chainable(fn) {
console.info('a', this);//window
return function () {
console.info('b1', this);
fn.apply(this, arguments);
console.info('b2', this);
return this;
};
}
var person = {
setName: chainable(function (name) {
console.log('c', this);
this.name = name;
})
,
sayName: chainable(function () {
console.log('d', this);
alert(this.name);
})
};
person.setName('Kevin Yue').sayName(); // Kevin Yue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment