Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 7 years ago

#4536 closed enhancement (wontfix)

jQuery.isFunction fix for built-in IE functions

Reported by: leidegre Owned by:
Priority: trivial Milestone: 1.3.2
Component: core Version: 1.3.2
Keywords: Utilities/jQuery.isFunction Cc:
Blocked by: Blocking:

Description

I found some background information on the typeof built-in DOM function problem in IE, and there's a plausible workaround for this.

The typeof these functions is "object", but the toString representation for IE is "\nfunction..." which a simple regular expression could catch. e.g.

// where this.context == <form/>
alert(^function/m.test(""+this.context.reset)); // true!

The multiline flag is necessary becuase IE adds a new line just before the "function" keyword.

If the typeof is not "object", then the above does not apply, so, any malformed string can not evaluate as a "function". But an object, where the toString function returns a string that starts with "function" would. Maybe there's a workaround for that to, but this slight modification of the jQuery.isFunction function does make it a lot more useful (compatibility wise).

Change History (6)

comment:1 Changed 11 years ago by leidegre

This ticket addresses the issue found inticket #2968.

comment:2 in reply to:  description Changed 11 years ago by leidegre

This is my purposed fix (targeting the jquery-1.3.2.min.js release), ehm, hack for built-in DOM functions in IE.

isFunction:function(E){return $.browser.msie&&
s.call(E)==="[object Object]"?/^function/m.test(""+E):
s.call(E)==="[object Function]"}

comment:3 Changed 11 years ago by dmethvin

The IE case was left out intentionally because although it has some function-like properties is is not a proper Javascript Function object -- it does not support .apply() for example. Earlier versions of jQuery.isFunction tried to accomodate these cases but it was a mess.

Have you encountered a situation where this causes a problem?

comment:4 Changed 11 years ago by leidegre

No,

but I was writing some plugin code to submit form with ajax when I wanted to clear/reset the form. While it's possible to do with jQuery, I wanted to use the reset method, specified by the DOM.

To check if the HTMLFormElement supports the reset() method, I had to use this trick to make it work in IE. My clear/reset plugin fallback to jQuery just setting the values to nothing, but the idea was that it would be better to rely on the reset method, since it there and it does exactly what I want.

I can't really find any decent documentation on it's availability cross browsers, but it seems pretty much safe to just use it, and assume that it's implemented in all browsers.

comment:5 Changed 11 years ago by brandon

Resolution: wontfix
Status: newclosed

As dmethvin stated, this functionality was intentionally removed from jQuery and is documented as such. The workaround is as simple as wrapping the native function in an anonymous function.

comment:6 Changed 7 years ago by James M. Greene

So I know this is obscenely late and all... but I just ran into this issue for the first time the other day. As a result, I created a new jQuery plugin to detect browser-native host object methods/functions.

jquery.isNativeFunction: http://plugins.jquery.com/isNativeFunction/

It is compatible with jQuery 1.0.x through jQuery 2.0.x. I have no expectations of it becoming incompatible with future versions anytime soon (i.e. even without maintenance on my part) given the small subset of jQuery functionality that it leverages.

Note: See TracTickets for help on using tickets.