Function declaration in CoffeeScript

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

Static classes and methods in coffeescript

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

How do I get the Back Button to work with an AngularJS ui-router state machine?

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