updated to use the Flanagan / Miller device

This commit is contained in:
AJ ONeal 2010-11-30 01:14:36 -07:00
parent 0ae8f8cd7e
commit 99e5007e0f
3 changed files with 12 additions and 7 deletions

View File

@ -9,6 +9,12 @@ This works in both the Browser and SSJS.
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
====

View File

@ -5,9 +5,7 @@
var s = typeof value;
if (s === 'object') {
if (value) {
if (typeof value.length === 'number' &&
!(value.propertyIsEnumerable('length')) &&
typeof value.splice === 'function') {
if ((/array/i).test(({}).toString.call(value))) {
s = 'array';
}
} else {

View File

@ -1,6 +1,6 @@
// Firefox was tested using persevere's global-es5 for es5 emulation
(function () {
require('remedial');
require('../lib/remedial');
a = [];
a[2] = 27;
@ -24,7 +24,8 @@
// Expected: 3
// Node/V8/FF: 0
console.log(typeOf(b));
// array
// Expected: Object
// Node/V8/FF: array (with Crockford's original)
c = Object.create([]);
@ -39,7 +40,7 @@
// Expected: 3
// Node/V8/FF: 1
console.log(typeOf(c));
// Expected: array
// Expected: object
// Node/V8/FF: object
@ -53,7 +54,7 @@
// Expected: 3
// Node/V8/FF: 1
console.log(typeOf(d));
// Expected: array
// Expected: object
// Node/V8: object
}());