Created
December 1, 2011 08:14
-
-
Save dherman/1414896 to your computer and use it in GitHub Desktop.
Variation on Bob's monocle-mustache, using parens instead of braces
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
// inspired by https://github.com/raganwald/homoiconic/blob/master/2011/11/sans-titre.md#readme | |
// and by https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/611c04100ac17142 | |
// 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)); | |
// object initialization with cascades: | |
this.(foo = 12, | |
bar = "hello", | |
mumble = false); | |
// Bob's compound example: | |
document.query('#myTable').(queryAll('.firstColumn').(style.(background = 'red', | |
border = '2px solid black'), | |
text = 'first column'), | |
queryAll('.lastColumn').(style.background = 'blue', | |
text = 'last column')); | |
// or perhaps reindented like so: | |
document.query('#myTable').( | |
queryAll('.firstColumn').( | |
style.( | |
background = 'red', | |
border = '2px solid black'), | |
text = 'first column'), | |
queryAll('.lastColumn').( | |
style.background = 'blue', | |
text = 'last column')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment