Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created September 28, 2012 14:26
Show Gist options
  • Save shaneriley/3800176 to your computer and use it in GitHub Desktop.
Save shaneriley/3800176 to your computer and use it in GitHub Desktop.
Ruby-like iteration in Javascript
var œ = function(number) {
return {
times: {
length: number,
"do": function(fn) {
var len = this.length;
for (var i = 0; i < len; i++) {
fn(i);
}
}
}
};
};
œ(20).times.do(function(i) { console.log(i); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment