Skip to content

Instantly share code, notes, and snippets.

@danday74
Last active February 6, 2016 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danday74/2357cd3c35f2b5d76816 to your computer and use it in GitHub Desktop.
Save danday74/2357cd3c35f2b5d76816 to your computer and use it in GitHub Desktop.
JavaScript chaining 1
var _ = require('underscore');
function MyClass() {
this.prop1 = {};
this.prop2 = {};
this.prop3 = {};
}
MyClass.prototype.func1 = function (obj) {
var self = this;
_.extend(self.prop1, obj);
return self;
};
MyClass.prototype.func2 = function (obj) {
var self = this;
_.extend(self.prop1, obj);
_.extend(self.prop2, obj);
return self;
};
MyClass.prototype.func3 = function (obj) {
var self = this;
_.extend(self.prop1, obj);
_.extend(self.prop3, obj);
return self;
};
var me = new MyClass();
me.func1({fred:5}).func2({jim:7}).func3({tim:9});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment