for (var key in object) in CoffeeScript? [duplicate]
for key of object Try it in js2coffee
for key of object Try it in js2coffee
You could also try Batsh, which is a DSL (Domain-Specific Language) that compiles a C-syntax language to Bash (and Windows Batch). Project Online demo
value = if maxValue > minValue then minValue else maxValue
isnt is the opposite of is, which is the triple equals sign. Just negate the in: if err and user not in moderators return or, using postfix if: return if err and user not in moderators
NOTE: This question had two parts, but because the title was “Environment detection: node.js or browser” – I will get to this part first, because I guess many people are coming here to look for an answer to that. A separate question might be in order. In JavaScript variables can be redefined by the inner … Read more
CoffeeScript uses function declarations (aka “named functions”) in just one place: class definitions. For instance, class Foo compiles to var Foo; Foo = (function() { function Foo() {} return Foo; })(); The reason CoffeeScript doesn’t use function declarations elsewhere, according to the FAQ: Blame Microsoft for this one. Originally every function that could have a … Read more
classes are just functions so they create scopes. everything defined inside this scope won’t be visible from the outside. class Foo # this will be our private method. it is invisible # outside of the current scope foo = -> “foo” # this will be our public method. # note that it is defined with … Read more
You can define class methods by prefixing them with @: class Box2DUtility constructor: () -> @drawWorld: (world, context) -> alert ‘World drawn!’ # And then draw your world… Box2DUtility.drawWorld() Demo: http://jsfiddle.net/ambiguous/5yPh7/ And if you want your drawWorld to act like a constructor then you can say new @ like this: class Box2DUtility constructor: (s) -> … Read more
Note The answers that suggest using variations of $window.history.back() have all missed a crucial part of the question: How to restore the application’s state to the correct state-location as the history jumps (back/forward/refresh). With that in mind; please, read on. Yes, it is possible to have the browser back/forward (history) and refresh whilst running a … Read more
While you can just use parentheses (e.g. (-> foo)(), you can avoid them by using the do keyword: do f = -> console.log ‘this runs right away’ The most common use of do is capturing variables in a loop. For instance, for x in [1..3] do (x) -> setTimeout (-> console.log x), 1 Without the … Read more