mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Change Base.isObject() to also check for instances of plain Base objects, and rename it to Base.isPlainObject().
This commit is contained in:
parent
2abefee336
commit
24b5f870bd
5 changed files with 14 additions and 8 deletions
12
lib/bootstrap.js
vendored
12
lib/bootstrap.js
vendored
|
@ -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) {
|
||||
|
|
|
@ -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]))
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue