FYI, we have just landed an updated Object.isFunction few days ago. It
now returns false for regexp objects and works around WebKit's
NodeList issue. 
http://github.com/sstephenson/prototype/commit/436a694dc1c30d3dc2bf262f63f8b34c65113439

As far as OP goes, first we all need to "define what a function is".

Is it something that implements call/apply? (then window.alert is not
the function)
Is it something that returns "function" when applied "typeof"? (then
window.alert is still not a function)
Is it something that implements internal [[Call]] property?

I'm more towards the third one, but then the method should be called:
"Object.isCallable"
The problem here is that although specs state that typeof should
return "object" for those expressions which DON'T implement internal
[[Call]], IE seems, once again, to go against the world.

- kangax

On Jun 6, 8:23 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> Yeah, Richard's approach would be about eight times more elegant...if
> there were something reliable to test for.  It can be IE-specific, of
> course.  I was sure when I saw his post that there would be
> *something* we could check for, but none of the things that come to
> mind are both present (IE doesn't have arity) and sufficiently unique
> (see Kangax's comments about call, apply, etc.).  (BTW, don't try to
> iterate the properties of an intrinsic function object using for..in
> with IE6 on XP; Bad Things happen.)
>
> Sadly my big list approach just won't work, it will always have holes
> in it.  For example:
>
>     var x = document.createElement("p");
>     if (Object.isFunction(x.getAttribute)) { ... }
>
> So between the holes and the bloat involved in handling even the ones
> we could handle, I'd say we just mention it in Object.isFunction's
> docs and move on, until/unless someone finds the magic thing.
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Jun 6, 12:51 pm, kangax <[EMAIL PROTECTED]> wrote:
>
> > I wish it was that easy : ) Unfortunately, we can't really account for
> > all host objects, which are notorious for their incompliance with
> > specs (e.g. it's well known how some of them have no constructor
> > property, and others throw error when accessing certain properties).
> > Hardcoding few methods barely solves the problem.
> > We could of course check for "apply/call" members on an object, but
> > guess what - those are undefined as well : )
> > As far as I remember jQuery calls object's toString, then tests if
> > result contains "function". That's clever, but unreliable, as any
> > other object which defines "toString" to return something that
> > contains "function" will produce falsy results.
>
> > - kangax
>
> > On Jun 6, 6:08 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
>
> > > OMG, I can confirm this, on IE6 anyway.  (Couldn't they get *anything*
> > > right?  I mean, I know Firefox has its issues, but...  And yes,
> > > technically a function is an object, but that's no excuse.)
>
> > > The only workaround that immediately comes to mind is to actually have
> > > a list of these and compare against them in IE -- e.g.:
>
> > > isFunction: (function(){
> > >     if (typeof window.close == "object") {
> > >         // IE version, works around typeof returning "object" for
> > > intrinsic functions
> > >         return function(object) {
> > >             return (
> > >                 typeof object == "function"
> > >                 || object === window.close
> > >                 || object === document.getElementById
> > >                 // etc., etc., etc.
> > >             );
> > >         };
> > >     } else {
> > >         // Non-IE version, expects typeof to work correctly
> > >         return function(object) {
> > >             return typeof object == "function";
> > >         };
> > >     }
>
> > > })()
>
> > > Blech.  The more of this that happens, the more I want a separate file
> > > that only IE people have to download containing these workarounds...
> > > --
> > > T.J. Crowder
> > > tj / crowder software / com
>
> > > On Jun 6, 9:27 am, Viktor Kojouharov <[EMAIL PROTECTED]> wrote:
>
> > > > Here's quite the problem in IE.
>
> > > > For certain 'native' functions, like window.close, or
> > > > document.getElementById, typeof for those functions returns on object
> > > > in IE. Consequently, Object.isFunction will actually return false for
> > > > those functions.
>
> > > > Though there's probably little that can be done, I thought you guys
> > > > should know about it.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to