mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Add Base.readAll(), to repeatetly apply Base.read() on all elements of an array and return the result in a new array.
This commit is contained in:
parent
e0edddd5f6
commit
516557808e
1 changed files with 13 additions and 5 deletions
18
src/paper.js
18
src/paper.js
|
@ -55,20 +55,28 @@ this.install = function(scope) {
|
||||||
Base.inject({
|
Base.inject({
|
||||||
statics: true,
|
statics: true,
|
||||||
|
|
||||||
read: function(args, index, length) {
|
read: function(args, start, length) {
|
||||||
var index = index || 0, length = length || args.length - index;
|
var start = start || 0,
|
||||||
var arg = args[index];
|
length = length || args.length - start;
|
||||||
|
var arg = args[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, index > 0 || length < args.length
|
obj = obj.initialize.apply(obj, start > 0 || length < args.length
|
||||||
? Array.prototype.slice.call(args, index, index + length)
|
? Array.prototype.slice.call(args, start, start + length)
|
||||||
: args) || obj;
|
: args) || obj;
|
||||||
return 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));
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
capitalize: function(str) {
|
capitalize: function(str) {
|
||||||
return str.replace(/\b[a-z]/g, function(match) {
|
return str.replace(/\b[a-z]/g, function(match) {
|
||||||
return match.toUpperCase();
|
return match.toUpperCase();
|
||||||
|
|
Loading…
Reference in a new issue