updated to use the Flanagan / Miller device
This commit is contained in:
parent
0ae8f8cd7e
commit
99e5007e0f
|
@ -9,6 +9,12 @@ This works in both the Browser and SSJS.
|
||||||
|
|
||||||
require('remedial');
|
require('remedial');
|
||||||
|
|
||||||
|
Notes
|
||||||
|
----
|
||||||
|
|
||||||
|
This uses the ["Flanagan / Miller device"](http://groups.google.com/group/nodejs/msg/0670a986a2906aeb) rather than the Crockford's original.
|
||||||
|
|
||||||
|
There is [a more specific typeof()](http://rolandog.com/archives/2007/01/18/typeof-a-more-specific-typeof/) implementation worthy of consideration.
|
||||||
|
|
||||||
Globals
|
Globals
|
||||||
====
|
====
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
var s = typeof value;
|
var s = typeof value;
|
||||||
if (s === 'object') {
|
if (s === 'object') {
|
||||||
if (value) {
|
if (value) {
|
||||||
if (typeof value.length === 'number' &&
|
if ((/array/i).test(({}).toString.call(value))) {
|
||||||
!(value.propertyIsEnumerable('length')) &&
|
|
||||||
typeof value.splice === 'function') {
|
|
||||||
s = 'array';
|
s = 'array';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Firefox was tested using persevere's global-es5 for es5 emulation
|
// Firefox was tested using persevere's global-es5 for es5 emulation
|
||||||
(function () {
|
(function () {
|
||||||
require('remedial');
|
require('../lib/remedial');
|
||||||
|
|
||||||
a = [];
|
a = [];
|
||||||
a[2] = 27;
|
a[2] = 27;
|
||||||
|
@ -24,7 +24,8 @@
|
||||||
// Expected: 3
|
// Expected: 3
|
||||||
// Node/V8/FF: 0
|
// Node/V8/FF: 0
|
||||||
console.log(typeOf(b));
|
console.log(typeOf(b));
|
||||||
// array
|
// Expected: Object
|
||||||
|
// Node/V8/FF: array (with Crockford's original)
|
||||||
|
|
||||||
|
|
||||||
c = Object.create([]);
|
c = Object.create([]);
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
// Expected: 3
|
// Expected: 3
|
||||||
// Node/V8/FF: 1
|
// Node/V8/FF: 1
|
||||||
console.log(typeOf(c));
|
console.log(typeOf(c));
|
||||||
// Expected: array
|
// Expected: object
|
||||||
// Node/V8/FF: object
|
// Node/V8/FF: object
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@
|
||||||
// Expected: 3
|
// Expected: 3
|
||||||
// Node/V8/FF: 1
|
// Node/V8/FF: 1
|
||||||
console.log(typeOf(d));
|
console.log(typeOf(d));
|
||||||
// Expected: array
|
// Expected: object
|
||||||
// Node/V8: object
|
// Node/V8: object
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue