Re: Terminology: “non-method function”

Rick Waldron waldron.rick at gmail.com
Wed Apr 11 14:19:12 PDT 2012


On Wed, Apr 11, 2012 at 4:32 PM, Wes Garland <wes at page.ca> wrote:

> From a developer's POV - the terms bound/unbound makes a create deal of
> sense, since already have bind, which effectively turns an unbound function
> into a bound function.  It basically completes the thought and makes it
> easy to explain.
>

Absolutely agree


>
> Heck, it even makes this behaviour easy to explain:
>
> function ABC()
> {
>   this.hello = "world";
> }
> ABC.prototype.def = function() { alert(this.hello) };
> window.onclick = new ABC().def;
>
> Q: Why does my program alert undefined?
> A: The default behaviour for an event handler is to bind the event itself
> as 'this'.


Just to avoid any confusion, you'll actually get the event.currentTarget as
|this|

Rick


> If you wanted that program to alert "world", you should have used a *bound
> function* instead.
>
> Wes
>
> --
> Wesley W. Garland
> Director, Product Development
> PageMail, Inc.
> +1 613 542 2787 x 102
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120411/49ed18e3/attachment.html>


More information about the es-discuss mailing list