Created
July 1, 2014 20:26
-
-
Save christabor/e38dacf9aa2ba74218ea to your computer and use it in GitHub Desktop.
Fake chaining practice - js
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 d3 = function(){ | |
var self = this; | |
this.foo = function() { | |
return this; | |
}; | |
this.range = function(max) { | |
var x = []; | |
for(var i = 0 ; i < max; i++) { | |
x.push(i); | |
} | |
self.current_arr = x; | |
return this; | |
}; | |
this.doubleRange = function(range) { | |
if(!range) range = self.current_arr; | |
for(var i = 0, len = range.length; i < len; i++ ) { | |
range[i] = range[i] * 2; | |
}; | |
self.current_arr = range; | |
return this; | |
}; | |
this.nestWithEmpty = function(range) { | |
if(!range) range = self.current_arr; | |
for(var i = 0, len = range.length; i < len; i++ ) { | |
range[i] = [0, range[i]]; | |
}; | |
self.current_arr = range; | |
return this; | |
}; | |
}; | |
function init() { | |
var x = new d3(); | |
var res = x.foo() | |
.range(100) | |
.doubleRange() | |
.nestWithEmpty(); | |
console.log(res.current_arr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bit jankety, but interesting nonetheless.