I like the trick, specially because it makes easily "flat" values like
"false" and "new Boolean(false)", as example, and I guess a function like
this one could be useful as well, isn't it?

getNativeConstructor = function(toString, RegExp){return function(Object){
    return window[toString.call(Object).replace(RegExp, "$1")];
}}(Object.prototype.toString, /^.{8}([^\]]+)\]$/);

I am not sure about the window trick, maybe a string is enough for switches
and other checks

getNativeConstructor = function(toString, RegExp){return function(Object){
    return window[toString.call(Object).replace(RegExp, "$1")];
}}(Object.prototype.toString, /^.{8}([^\]]+)\]$/);

switch(getNativeConstructor(whatever)){
    case "Array": ...
    case "Boolean": ...
    case "Number": ...
}

Regards

On Thu, Oct 9, 2008 at 7:33 PM, Nathan Hammond <[EMAIL PROTECTED]>wrote:

>
> This showed up on Douglas Crockford's blog today:
> Object.prototype.toString.apply(value) === '[object Array]'
>
> The trick appears to have been in circulation for about 6 months and
> shows up in DWR as well as DC's book. DC credits Mark Miller for it.
> Probably slower than the value.constructor == Array test we use
> everywhere, but fixes the iframe-created object issue.
>
> 1. Should we adopt it for resiliency?
> 2. @Michael Geary: Are you using this in your iframe sandbox code? It
> sure would beat the heck out of duck typing.
>
> Just starting a discussion...
> Nathan
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to