Thanks Mark, so how is anyone supposed to be sure about or check a Brand in ES6 then?
On Fri, Nov 1, 2013 at 1:00 PM, Mark S. Miller <erig...@google.com> wrote: > > > > On Fri, Nov 1, 2013 at 12:16 PM, Andrea Giammarchi < > andrea.giammar...@gmail.com> wrote: > >> Allen I think we all agree duck typing is more flexible, powerful, easy, >> etc etc ... but since you mentioned, how would do distinguish between a >> `Map` and a `WeakMap` without passing through the branding check ? >> >> That's a very good example indeed, `'has' in obj` or `'set' in obj` does >> not grant you any behavior with the signature itself (e.g. `WekMap` >> does/did not accept primitives as key) >> >> AFAIK WebIDL is entirely based on branding, regardless it's a good or a >> bad thing, that's the way W3C describes "things" since quite ever (and >> implement them in Java too ... anyway) >> >> Why there's no easy way to check for branding if not abusing >> `Object.prototype.toString` ? >> >> If so many libraries are using it because of the cross realm, maybe there >> is a need for some similar mechanism and implemented in core would make >> everybody life easier/faster ? >> >> The option you give us is: keep abusing `Object.prototype.toString` ... >> that's OK but it seems to be a dirty solution. >> > > In ES5, Object.prototype.toString was a reliable brand check. It no longer > is in ES6. > > > >> >> Cheers >> >> >> >> >> On Fri, Nov 1, 2013 at 11:52 AM, Allen Wirfs-Brock <al...@wirfs-brock.com >> > wrote: >> >>> >>> On Nov 1, 2013, at 10:40 AM, Anne van Kesteren wrote: >>> >>> > On Fri, Nov 1, 2013 at 12:50 AM, Allen Wirfs-Brock >>> > <al...@wirfs-brock.com> wrote: >>> >> [isSpecialString]() {return isSpecialString in this}; >>> > >>> > So this is basically what we have for DOM objects right now. And what >>> > we're asking for is having this elevated to language-supported >>> > construct. Be it in the form of a method or something else. It's not >>> > really clear why sometimes you would use if "brand in obj" and other >>> > times "Array.isArray(obj)". Seems rather messy. >>> >>> Array.isArray is a legacy artifact so I'm not going to try to generalize >>> from it. >>> >>> But, in general, the distinction is between asking "does this object >>> appear to expose the behavior I need" and "is this object an instance of a >>> specific known implementation of the behavior I need". Let's call the >>> first question "duck typing" and the second "branding". Duck typing is a >>> weaker test but allows for a lot of flexibility and extensibility. Branding >>> gives you reliable knowledge about certain aspects of a branded object. >>> But it is less flexible and and systems that extensively using branding >>> are often harder to extend. IMO branding is over used. >>> >>> Array.isArray is a specific brand test based upon how the implementation >>> of how property definition interacts with the value of the 'length' >>> property. >>> >>> ES currently proves lots of ways to do duck type testing. Built-in >>> objects (including host objects) can implement branding and brand testing >>> using various techniques but ES currently (including ES6) is very limited >>> in its language level sort for reliable branding. The best we have to >>> offer in ES6 is WeakMaps. In the future, we probably will add mechanism >>> that make it easier to define branded objects defined via ES code. >>> >>> But, before you brand something really think carefully about why you >>> need such a brand. It may not really be necessary. >>> >>> Allen >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > > -- > Cheers, > --MarkM >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss