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) {
return toString.call(obj) === '[object Array]';
},
isObject = function(obj) {
return toString.call(obj) === '[object Object]';
},
slice = proto.slice,
forEach = proto.forEach || function(iter, bind) {
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.
each: each,
clone: clone,
define: define,
describe: describe,
iterator: iterator,
// Base.create does something different from Object.create, it only
// works on constructors and uses their prototype.
create: function(ctor) {
return create(ctor.prototype);
},
define: define,
describe: describe,
iterator: iterator,
isObject: isObject,
isObject: function(obj) {
return obj !== null && typeof obj === 'object'
&& Object.getPrototypeOf(obj) === Object.prototype;
},
check: function(obj) {
return !!(obj || obj === 0);