Ticket #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: | |
| Blocking: | Blocked by: |
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
comment:2 in reply to: ↑ description Changed 4 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 4 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 4 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.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This ticket addresses the issue found in ticket #2968.