mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Improve Base.readAll() to check entries for arrays and pass them to constructors as arguments rather than their containing array.
This commit is contained in:
parent
49645f8a0d
commit
6b4f142838
1 changed files with 13 additions and 10 deletions
23
src/paper.js
23
src/paper.js
|
@ -55,25 +55,28 @@ this.install = function(scope) {
|
||||||
Base.inject({
|
Base.inject({
|
||||||
statics: true,
|
statics: true,
|
||||||
|
|
||||||
read: function(args, start, length) {
|
read: function(list, start, length) {
|
||||||
var start = start || 0,
|
var start = start || 0,
|
||||||
length = length || args.length - start;
|
length = length || list.length - start;
|
||||||
var arg = args[start];
|
var arg = list[start];
|
||||||
// If the class defines _readNull, return null when nothing was provided
|
// If the class defines _readNull, return null when nothing was provided
|
||||||
if (arg instanceof this
|
if (arg instanceof this
|
||||||
|| this.prototype._readNull && arg == null && length <= 1)
|
|| this.prototype._readNull && arg == null && length <= 1)
|
||||||
return arg;
|
return arg;
|
||||||
var obj = new this(this.dont);
|
var obj = new this(this.dont);
|
||||||
obj = obj.initialize.apply(obj, start > 0 || length < args.length
|
obj = obj.initialize.apply(obj, start > 0 || length < list.length
|
||||||
? Array.prototype.slice.call(args, start, start + length)
|
? Array.prototype.slice.call(list, start, start + length)
|
||||||
: args) || obj;
|
: list) || obj;
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
|
|
||||||
readAll: function(args, start) {
|
readAll: function(list, start) {
|
||||||
var res = [];
|
var res = [], entry;
|
||||||
for (var i = start || 0, l = args.length; i < l; i++)
|
for (var i = start || 0, l = list.length; i < l; i++) {
|
||||||
res.push(this.read(args, i, 1));
|
res.push(Array.isArray(entry = list[i])
|
||||||
|
? this.read(entry, 0)
|
||||||
|
: this.read(list, i, 1));
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue