About isFunction
I lost the point where toString.call(obj) === "[object Function]" was
introduced instead of obj instanceof function
I understand differences in IE so I wonder if two distinct callbacks could
solve the odyssey:
isFunction: function( obj ) {
return obj instanceof Function;
},
isDOMFunction: toString.call(window.alert) === "[object Function]" ?
function( obj ) {
return toString.call(obj) === "[object Function]";
}:
// IE only and only until standard native function manifest
function( obj ){
return !!obj && typeof obj.toString === "undefined" &&
/^\s*\bfunction\b/.test(obj);
}
,
In this way we could consider that in every browser, and when call/apply are
supported, isFunction(fn) will guarantee call/apply while a DOMFunction
could require a try catch or a different behavior for IE
switch(true){
case $.isFunction(fn): return fn.call(what, ever);
case $.isDOMFunction(fn): what.push.call(what, toArray(fn(ever)));
return what;
default: throw new Error("what tf?");
}
... or maybe not?
Regards
On Sun, Jul 26, 2009 at 4:09 PM, Andrea Giammarchi <
[email protected]> wrote:
> I usually encapsulate toString from Object.prototype and if somebody breaks
> the rule it means we cannot trust anything included typeof. So, in few
> words, nobody has intersts into break this rule, imho.
>
> On Jul 26, 2009 8:07 AM, "DBJDBJ" <[email protected]> wrote:
>
>
> Also, IMHO this yields high level of encapsulation of an important
> mechanism.
> Which is a good thing.
> And it is a fraction of a micro second slower then
>
> Object.prototype.toString.call(x) === "[object Object]"
> but it is more compact ...
>
> In any case we are entering the subjective judgement phase, so I think
> we should stop here and leave it to jQuery team to use this or not...
>
> --DBJ On Jul 26, 12:09 am, Andrea Giammarchi <[email protected]>
> wrote:
>
> > I miss the point about regexp usage ... please tell me the difference (in
> a > real scenario) betwe...
>
> > On Sat, Jul 25, 2009 at 1:38 PM, DBJDBJ <[email protected]> wrote: > > >
> This indeed woks : functi...
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---