Side navigation
#12191 closed bug (fixed)
Opened August 03, 2012 07:24PM UTC
Closed November 24, 2012 10:23PM UTC
jQuery.type() should return "error" for native ECMAScript Error objects
Reported by: | sime.vidas@gmail.com | Owned by: | rwaldron |
---|---|---|---|
Priority: | low | Milestone: | 1.9 |
Component: | core | Version: | 1.8rc1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
ECMAScript defines 12 different [[Class]]
values - see [section 8.6.2](http://ecma-international.org/ecma-262/5.1/#sec-8.6.2). However, $.type()
only "recognizes" 8 of those 12 values. The 4 that it doesn't recognize are:
- "Arguments"
- "Error"
- "Math"
- "JSON"
I understand why jQuery ignores Math
, JSON
, or the arguments
object - their "type" can easily be comprehended based on their name.
What I don't understand is why $.type
refuses to recognize Error
objects.
$.type( new Error ) // "object", but should be "error"
Error
objects are one of the native ECMAScript types of objects. $.type
should be able to recognize them. To enable this recognition, all you have to do is add "Error" to the space-separated list here:
// Populate the class2type map jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); });
Like so:
// Populate the class2type map jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); });
The [[Class]]
value of all instances of any of the native Error
constructors (e.g. Error
, SyntaxError
, etc.) is "Error", so that this small change in the jQuery source code should make $.type
recognize all native Error
objects.
Btw, I have created a corresponding thread on Stack Oveflow - see here: http://stackoverflow.com/q/11797707/425275.
Attachments (0)
Change History (7)
Changed August 03, 2012 07:31PM UTC by comment:1
status: | new → open |
---|
Changed August 03, 2012 07:31PM UTC by comment:2
component: | unfiled → core |
---|---|
milestone: | None → 1.8 |
priority: | undecided → low |
version: | 1.7.2 → 1.8rc1 |
Changed August 03, 2012 07:35PM UTC by comment:3
Uh, I'm sorry, I don't know how to do that.
Changed August 03, 2012 07:56PM UTC by comment:4
owner: | → rwaldron |
---|---|
status: | open → assigned |
No worries, I'll grab this and get it patched.
Changed August 10, 2012 05:53PM UTC by comment:5
milestone: | 1.8 → 1.8.1 |
---|
Changed August 27, 2012 01:50PM UTC by comment:6
milestone: | 1.8.1 → 1.9 |
---|
Agree. Can you add them, along with supporting tests and make a pull request?