I think the question is legit and this is a weak check

`'throw' in possibleGenerator`

specially if you have Dictionary like objects around ...

'length' in object does not tell you much, does it?

`Object.prototype.toString` is abused all over client/server
libraries/utilities since ducks sometimes might look like gooses too.

So eventually would you don't want developers to really know what they are
dealing with and promote weak feature detections instead? It might work,
but that ain't secure.

I still prefer `instanceof` for better performance since I don't usually
work with different realm but I also would like to have an
`Object.is(SomeClass, object);` facility instead of the boring, slow, and
inappropriate `{}.toString.call(obj)` check.

Just my thoughts, as usual.


On Thu, Oct 31, 2013 at 11:01 AM, Allen Wirfs-Brock
<al...@wirfs-brock.com>wrote:

>
> On Oct 31, 2013, at 9:43 AM, Brandon Benvie wrote:
>
> > On 10/31/2013 8:50 AM, David Bruant wrote:
> >> I'm not sure it's worth making it work for jQuery. This is trying to
> make a good use of same-origin multi-global which shouldn't exist in the
> first place. Keeping same-origin access as it is and encouraging people to
> add @sandbox even on same-origin iframes seems like a better idea.
> >>
> >> Should the addition be a nicer Object.prototype.toString.call?
> >
> > You're right, it's not instanceof. But I definitely think the argument
> can be made that there is a need for checking if something is of a certain
> class. I'm finding myself wanting things like `isGenerator` and
> `isGeneratorFunction`, for example. There's countless examples of people
> re-purposing Object.prototype.toString to serve this functionality ad hoc.
>
>
> What are the use cases for things like 'isGenerator'. When and why would
> you need to know that an object  upon which you are going to invoke the
> Iterator interface was/wasn't implemented by a generator.  If the reason is
> to know whether or not you can use the throw method (the only real
> difference between the generator object interface and the Iterator
> interface) you can test:
>     'throw' in possibleGenerator
>
> In general this sort of isFoo or obj.constructor === Foo class test is a
> bad smell in dynamic class based languages and tends to be a reflection of
> static nominal type thinking (which is fine in its own context, but JS is
> has a dynamic class model).
>
> Allen
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to