From 9c9a2d731fea9679f65904a3a6b72dd78b4253a4 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 9 Jan 2006 03:40:59 +0000 Subject: Update library --- framework/Web/Javascripts/prototype/array.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'framework/Web/Javascripts/prototype/array.js') diff --git a/framework/Web/Javascripts/prototype/array.js b/framework/Web/Javascripts/prototype/array.js index 397afbbf..f5694c05 100644 --- a/framework/Web/Javascripts/prototype/array.js +++ b/framework/Web/Javascripts/prototype/array.js @@ -1,4 +1,5 @@ var $A = Array.from = function(iterable) { + if (!iterable) return []; if (iterable.toArray) { return iterable.toArray(); } else { @@ -11,12 +12,19 @@ var $A = Array.from = function(iterable) { Object.extend(Array.prototype, Enumerable); +Array.prototype._reverse = Array.prototype.reverse; + Object.extend(Array.prototype, { _each: function(iterator) { for (var i = 0; i < this.length; i++) iterator(this[i]); }, + clear: function() { + this.length = 0; + return this; + }, + first: function() { return this[0]; }, @@ -48,16 +56,21 @@ Object.extend(Array.prototype, { indexOf: function(object) { for (var i = 0; i < this.length; i++) if (this[i] == object) return i; - return false; + return -1; }, - reverse: function() { - var result = []; - for (var i = this.length; i > 0; i--) - result.push(this[i-1]); - return result; + reverse: function(inline) { + return (inline !== false ? this : this.toArray())._reverse(); }, + shift: function() { + var result = this[0]; + for (var i = 0; i < this.length - 1; i++) + this[i] = this[i + 1]; + this.length--; + return result; + }, + inspect: function() { return '[' + this.map(Object.inspect).join(', ') + ']'; } -- cgit v1.2.3