Skip to content

Instantly share code, notes, and snippets.

@christabor
Created July 1, 2014 20:26
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 christabor/e38dacf9aa2ba74218ea to your computer and use it in GitHub Desktop.
Save christabor/e38dacf9aa2ba74218ea to your computer and use it in GitHub Desktop.
Fake chaining practice - js
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);
}
@christabor
Copy link
Author

This is a bit jankety, but interesting nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment