mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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({
|
||||
statics: true,
|
||||
|
||||
read: function(args, start, length) {
|
||||
read: function(list, start, length) {
|
||||
var start = start || 0,
|
||||
length = length || args.length - start;
|
||||
var arg = args[start];
|
||||
length = length || list.length - start;
|
||||
var arg = list[start];
|
||||
// If the class defines _readNull, return null when nothing was provided
|
||||
if (arg instanceof this
|
||||
|| this.prototype._readNull && arg == null && length <= 1)
|
||||
return arg;
|
||||
var obj = new this(this.dont);
|
||||
obj = obj.initialize.apply(obj, start > 0 || length < args.length
|
||||
? Array.prototype.slice.call(args, start, start + length)
|
||||
: args) || obj;
|
||||
obj = obj.initialize.apply(obj, start > 0 || length < list.length
|
||||
? Array.prototype.slice.call(list, start, start + length)
|
||||
: list) || obj;
|
||||
return obj;
|
||||
},
|
||||
|
||||
readAll: function(args, start) {
|
||||
var res = [];
|
||||
for (var i = start || 0, l = args.length; i < l; i++)
|
||||
res.push(this.read(args, i, 1));
|
||||
readAll: function(list, start) {
|
||||
var res = [], entry;
|
||||
for (var i = start || 0, l = list.length; i < l; i++) {
|
||||
res.push(Array.isArray(entry = list[i])
|
||||
? this.read(entry, 0)
|
||||
: this.read(list, i, 1));
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue