- Creates array of strings separated by spaces, like Ruby’s.
/** bs **/ $bar << <li>foo << <li>bar;
/** js **/ $bar.append('<li>foo').append('<li>bar');
This is cool because: it makes it easier and more readable to construct your HTML programmatically, otherwise you get lots of nested brackets.
Note, this operator is a little unfortunate considering the angular brackets of the inline HTML, so we should think of something better.
Use parenthesis to append at different levels in the DOM:
$bar << (<ol> << <li>#{foo} << <li>#{bar});
/** bs **/ [1,2,3].map{ |x| x * 2 }.each{ |x| console.log(x); }
/** js **/ [1,2,3].map(function(x){ return x * 2; }).each(function(x){ console.log(x); })
- Rationale: less visual noise
- Make the “context” of the map call be the iterated element
return&log foo;
- returns the value, but logs it first.
We have Inline HTML, so we should also support inline CSS, but let’s do it with SCSS and then (with a bit of effort), support having variables in both the JS and the CSS.
This is common to compile-to-JavaScript languages. But I’m not sure about it as—frankly—it doesn’t feel very “Javascripty”.
function foo() try {
bar();
} catch (e) {
console.error(e);
}
Becomes:
function foo() { try {
bar();
} catch (e) {
console.error(e);
}}