Last active
February 6, 2016 23:54
-
-
Save danday74/2357cd3c35f2b5d76816 to your computer and use it in GitHub Desktop.
JavaScript chaining 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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