diff --git a/lib/bootstrap.js b/lib/bootstrap.js index dd50cdc3..453660a3 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -315,9 +315,15 @@ var Base = new function() { // Bootstrap scope return create(ctor.prototype); }, - isObject: function(obj) { - return obj !== null && typeof obj === 'object' - && Object.getPrototypeOf(obj) === Object.prototype; + /** + * Returns true if obj is a plain JavaScript object literal, or a + * plain Base object, as produced by Base.merge(). + */ + isPlainObject: function(obj) { + var proto = obj !== null && typeof obj === 'object' + && Object.getPrototypeOf(obj); + return proto && (proto === Object.prototype + || proto === Base.prototype); }, check: function(obj) { diff --git a/src/browser/DomElement.js b/src/browser/DomElement.js index a887b6f7..ed886f67 100644 --- a/src/browser/DomElement.js +++ b/src/browser/DomElement.js @@ -38,7 +38,7 @@ var DomElement = new function() { continue; } // Do we have attributes? - if (Base.isObject(nodes[i])) + if (Base.isPlainObject(nodes[i])) DomElement.set(el, nodes[i++]); // Do we have children? if (Array.isArray(nodes[i])) diff --git a/src/core/Base.js b/src/core/Base.js index 86a00563..67179b4d 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -200,7 +200,7 @@ this.Base = Base.inject(/** @lends Base# */{ res = []; for (var i = 0, l = obj.length; i < l; i++) res[i] = Base.serialize(obj[i], true); - } else if (Base.isObject(obj)) { + } else if (Base.isPlainObject(obj)) { res = {}; for (var i in obj) if (obj.hasOwnProperty(i)) @@ -235,7 +235,7 @@ this.Base = Base.inject(/** @lends Base# */{ res = Base.create(type); res.initialize.apply(res, args); } - } else if (Base.isObject(obj)) { + } else if (Base.isPlainObject(obj)) { res = {}; for (var key in obj) res[key] = Base.deserialize(obj[key]); diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 3a7f43d6..a77686c9 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -146,7 +146,7 @@ var PaperScript = this.PaperScript = new function() { if (Array.isArray(value)) { for (var i = 0, l = value.length; i < l; i++) walkAst(value[i]); - } else if (Base.isObject(value)) { + } else if (Base.isPlainObject(value)) { walkAst(value); } } diff --git a/src/item/Item.js b/src/item/Item.js index 7ae94a0f..29805721 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -123,7 +123,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ // one object literal describing all the properties to be set on the created // instance. _setProperties: function(props) { - if (Base.isObject(props)) + if (Base.isPlainObject(props)) return this.set(props); },