Improve Base.isObject() to only return true for real "vanilla" JS objects.

This commit is contained in:
Jürg Lehni 2012-12-23 16:21:18 +01:00
parent 1046e440e8
commit 81b8a57a7c

16
lib/bootstrap.js vendored
View file

@ -19,9 +19,6 @@ var Base = new function() { // Bootstrap scope
isArray = Array.isArray = Array.isArray || function(obj) { isArray = Array.isArray = Array.isArray || function(obj) {
return toString.call(obj) === '[object Array]'; return toString.call(obj) === '[object Array]';
}, },
isObject = function(obj) {
return toString.call(obj) === '[object Object]';
},
slice = proto.slice, slice = proto.slice,
forEach = proto.forEach || function(iter, bind) { forEach = proto.forEach || function(iter, bind) {
for (var i = 0, l = this.length; i < l; i++) for (var i = 0, l = this.length; i < l; i++)
@ -325,15 +322,20 @@ var Base = new function() { // Bootstrap scope
// Expose some local privates as Base generics. // Expose some local privates as Base generics.
each: each, each: each,
clone: clone, clone: clone,
define: define,
describe: describe,
iterator: iterator,
// Base.create does something different from Object.create, it only // Base.create does something different from Object.create, it only
// works on constructors and uses their prototype. // works on constructors and uses their prototype.
create: function(ctor) { create: function(ctor) {
return create(ctor.prototype); return create(ctor.prototype);
}, },
define: define,
describe: describe, isObject: function(obj) {
iterator: iterator, return obj !== null && typeof obj === 'object'
isObject: isObject, && Object.getPrototypeOf(obj) === Object.prototype;
},
check: function(obj) { check: function(obj) {
return !!(obj || obj === 0); return !!(obj || obj === 0);