Hi John,
Your particular syntactic choice looks clever, but as is often the case, it
fails because of semicolon insertion. The following works today on any ES5
system:
> function foo() { > return this.function() > { > console.log('oops'); > };
> }
> foo.call({function: function(){return 'gotcha';}});
gotcha
On Thu, Dec 29, 2011 at 10:54 AM, John J Barton <[email protected]
> wrote:
> Sorry if this has been suggested before....
>
> I've stopped using the 'self=this' trick:
> ...
> var self = this;
> window.addEventListener('load', function(event) {
> self.foo();
> }, false);
>
> in favor of bind():
> ...
> window.addEventListener('load', function(event) {
> this.foo();
> }.bind(this), false);
>
> It's fine, but I wonder if such code would be clearer if we could write:
> ...
> window.addEventListener('load', this.function(event) {
> this.foo();
> }, false);
>
> To me at least this more closely expresses my intent: I want an anonymous
> method of 'this' object, not an anonymous function.
>
> jjb
>
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
--
Cheers,
--MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss