{ setX: function(x) { this._x = x; } } // works as expected { setX: (x) => { this._x = x; } } // haha nope, corrupts `window` probably
-
-
-
var a = { setX: (x) => { this._x = x; } }; a.setX(67); console.log(a._x); // undefined console.log(window._x); // 67
- 9 more replies
New conversation -
-
-
@qntm yea :( but they do arguably better things with 'this' that original js did.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@qntm it’s half the reason they were introduced, though. For the throwaway functions-within-functions that don’t need a ‘this’.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@qntm freeing us from constant ‘var self = this’ or ‘function () {}.bind(this)’.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@qntm Both define functions, rather than methods. If i didn't know JS i'd expect this to be undefined in both cases.Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.