From 516557808ee8507a64b7759959e7cb7bc9936d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 3 May 2011 08:59:55 +0100 Subject: [PATCH] Add Base.readAll(), to repeatetly apply Base.read() on all elements of an array and return the result in a new array. --- src/paper.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/paper.js b/src/paper.js index c1d00105..c0275138 100644 --- a/src/paper.js +++ b/src/paper.js @@ -55,20 +55,28 @@ this.install = function(scope) { Base.inject({ statics: true, - read: function(args, index, length) { - var index = index || 0, length = length || args.length - index; - var arg = args[index]; + read: function(args, start, length) { + var start = start || 0, + length = length || args.length - start; + var arg = args[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, index > 0 || length < args.length - ? Array.prototype.slice.call(args, index, index + length) + obj = obj.initialize.apply(obj, start > 0 || length < args.length + ? Array.prototype.slice.call(args, start, start + length) : args) || 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) { return str.replace(/\b[a-z]/g, function(match) { return match.toUpperCase();