Skip to content

Instantly share code, notes, and snippets.

@dherman
Created December 1, 2011 07:22
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 dherman/1414609 to your computer and use it in GitHub Desktop.
Save dherman/1414609 to your computer and use it in GitHub Desktop.
cascade syntax for JS
// 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment