mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -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);
|
return create(ctor.prototype);
|
||||||
},
|
},
|
||||||
|
|
||||||
isObject: function(obj) {
|
/**
|
||||||
return obj !== null && typeof obj === 'object'
|
* Returns true if obj is a plain JavaScript object literal, or a
|
||||||
&& Object.getPrototypeOf(obj) === Object.prototype;
|
* 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) {
|
check: function(obj) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ var DomElement = new function() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Do we have attributes?
|
// Do we have attributes?
|
||||||
if (Base.isObject(nodes[i]))
|
if (Base.isPlainObject(nodes[i]))
|
||||||
DomElement.set(el, nodes[i++]);
|
DomElement.set(el, nodes[i++]);
|
||||||
// Do we have children?
|
// Do we have children?
|
||||||
if (Array.isArray(nodes[i]))
|
if (Array.isArray(nodes[i]))
|
||||||
|
|
|
@ -200,7 +200,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
res = [];
|
res = [];
|
||||||
for (var i = 0, l = obj.length; i < l; i++)
|
for (var i = 0, l = obj.length; i < l; i++)
|
||||||
res[i] = Base.serialize(obj[i], true);
|
res[i] = Base.serialize(obj[i], true);
|
||||||
} else if (Base.isObject(obj)) {
|
} else if (Base.isPlainObject(obj)) {
|
||||||
res = {};
|
res = {};
|
||||||
for (var i in obj)
|
for (var i in obj)
|
||||||
if (obj.hasOwnProperty(i))
|
if (obj.hasOwnProperty(i))
|
||||||
|
@ -235,7 +235,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
res = Base.create(type);
|
res = Base.create(type);
|
||||||
res.initialize.apply(res, args);
|
res.initialize.apply(res, args);
|
||||||
}
|
}
|
||||||
} else if (Base.isObject(obj)) {
|
} else if (Base.isPlainObject(obj)) {
|
||||||
res = {};
|
res = {};
|
||||||
for (var key in obj)
|
for (var key in obj)
|
||||||
res[key] = Base.deserialize(obj[key]);
|
res[key] = Base.deserialize(obj[key]);
|
||||||
|
|
|
@ -146,7 +146,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
for (var i = 0, l = value.length; i < l; i++)
|
for (var i = 0, l = value.length; i < l; i++)
|
||||||
walkAst(value[i]);
|
walkAst(value[i]);
|
||||||
} else if (Base.isObject(value)) {
|
} else if (Base.isPlainObject(value)) {
|
||||||
walkAst(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
|
// one object literal describing all the properties to be set on the created
|
||||||
// instance.
|
// instance.
|
||||||
_setProperties: function(props) {
|
_setProperties: function(props) {
|
||||||
if (Base.isObject(props))
|
if (Base.isPlainObject(props))
|
||||||
return this.set(props);
|
return this.set(props);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue