3 ms·
>> "The behavior I just described makes `this` is almost useless in Javascript closures" Hmm?? e.onmouseover = function(c) {return function() { c.dosomething(
by axod 18y ago
>> "The behavior I just described makes `this` is almost useless in Javascript closures"
Hmm??
e.onmouseover = function(c) {return function() { c.dosomething()}}(this);
Then in the dosomething function, "this" references what you expect...
I don't see why you need a library to construct a simple closure.
- fh 18y agoNote how you haven't used the keyword `this` inside the closure. What you've written is functionally equivalent to the technique I described, assigning the `this` object to a temporary variable. The only difference is that you bind it with a lambda instead of a `var`.
- axod 18y agoI don't use the keyword this inside the closure, but inside the function dosomething() I can happily use "this".