public
Created

cascade syntax for JS

  • Download Gist
cascade.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme
 
// traditional method chaining with combinators:
console.log(range(1, 3)
.concat(range(4, 6))
.map(function(x) { return x * x })
.filter(function(x) { return x % 2 === 0 })
.reverse());
 
// method chaining with cascades:
array
->pop()
->pop()
->pop();
 
path
->moveTo(10, 10)
->stroke("red")
->fill("blue")
->ellipse(50, 50);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.