Opened 11 years ago
Closed 11 years ago
#12191 closed bug (fixed)
jQuery.type() should return "error" for native ECMAScript Error objects
Reported by: | Owned by: | Rick Waldron | |
---|---|---|---|
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.
Change History (7)
comment:1 Changed 11 years ago by
Status: | new → open |
---|
comment:2 Changed 11 years ago by
Component: | unfiled → core |
---|---|
Milestone: | None → 1.8 |
Priority: | undecided → low |
Version: | 1.7.2 → 1.8rc1 |
comment:4 Changed 11 years ago by
Owner: | set to Rick Waldron |
---|---|
Status: | open → assigned |
No worries, I'll grab this and get it patched.
comment:5 Changed 11 years ago by
Milestone: | 1.8 → 1.8.1 |
---|
comment:6 Changed 11 years ago by
Milestone: | 1.8.1 → 1.9 |
---|
comment:7 Changed 11 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fix #12191. jQuery.type should return "error" for Error objects.
Changeset: 67df705bf5205fa075ba6ceee2d7fd4763894a16
Agree. Can you add them, along with supporting tests and make a pull request?