JavaScript is quirky but that is why I like it. Unfortunately, there is a lot of problems for amateur developers if they don't take the time to learn the language.
These solutions are transcribed from past notes on stepping over quirky pitfalls
ProperScript (ClassicScript) removes first argument and sets it as var on first line
fn (self, b, c) {
}
TO
fn (b, c) {
var self = this;
}
On instantiation, all methods must be bound to this
fn A() {
this.b = this.b.bind(this);
}
Coffeescript harder to read due to lack of parentheses and braces to distinguish sections
The other reason for switching that people usually state is length of
function
. This choses to employfn
and side-step passing context around via fat arrows.