Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
function chainable(fn) {'a', this);//window
return function () {'b1', this);
fn.apply(this, arguments);'b2', this);
return this;
var person = {
setName: chainable(function (name) {
console.log('c', this); = name;
sayName: chainable(function () {
console.log('d', this);
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