Arrow binding

David Herman dherman at mozilla.com
Tue Apr 24 13:31:58 PDT 2012


On Apr 24, 2012, at 9:51 AM, Rick Waldron wrote:

> On Tue, Apr 24, 2012 at 12:33 PM, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
> On Mon, Apr 23, 2012 at 3:36 PM, David Herman <dherman at mozilla.com> wrote:
> >
> >    box = {
> >        _value: 0,
> >        get: () -> this._value,
> >        set(v) { this._value = v }
> >    }
> 
> I don't understand this example.  What is "set(v) {...}"?  It's not a
> setter, because it's not associated with a property name.  Assuming
> you meant "set value(v) {...}", why not just use an ordinary getter as
> well?
> 
> When I read this, I assumed it was a reference to this: http://wiki.ecmascript.org/doku.php?id=harmony:object_literals#object_literal_property_shorthands

Right. Thanks for providing the reference.

> Which would produce a method named "set" on "box"
> 
> > box.set(42)
> > box.get()
> 
> 42
> 
> The example is easily confused. 

Yeah, my bad. I was trying to demonstrate several syntaxes but shouldn't've picked an example with a method named "set". To clarify the example:

    box = {
        _value: 0,
        unbox: () -> this._value,
        setbox(v) { this._value = v }
    }

Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120424/23d31160/attachment.html>


More information about the es-discuss mailing list