Side navigation
#4536 closed enhancement (wontfix)
Opened April 14, 2009 01:59PM UTC
Closed May 03, 2009 05:58PM UTC
Last modified July 17, 2013 03:53AM UTC
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).
Attachments (0)
Change History (6)
Changed April 14, 2009 02:11PM UTC by comment:1
Changed April 14, 2009 02:42PM UTC by comment:2
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]"}
Changed April 14, 2009 04:04PM UTC by comment:3
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.isFunctiontried to accomodate these cases but it was a mess.
Have you encountered a situation where this causes a problem?
Changed April 14, 2009 04:26PM UTC by comment:4
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.
Changed May 03, 2009 05:58PM UTC by comment:5
resolution: | → wontfix |
---|---|
status: | new → closed |
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.
Changed July 17, 2013 03:53AM UTC by comment:6
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.
This ticket addresses the issue found in[http://dev.jquery.com/ticket/2968 ticket #2968].