From 4d75cb74d7fe952fda91395fa0b66dac499f6554 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Mon, 18 Feb 2013 16:18:09 +0800 Subject: [PATCH] Add some array methods for List --- lib/list.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/list.js b/lib/list.js index 53476458..3de6daec 100644 --- a/lib/list.js +++ b/lib/list.js @@ -115,6 +115,13 @@ if (_) { }); } +['slice', 'forEach'].forEach(function (method) { + var slice = [].slice; + List.prototype[method] = function () { + return Array.prototype[method].apply(this.items, slice.call(arguments)); + }; +});; + List.prototype.toObject = function() { return this.items; }; @@ -154,10 +161,6 @@ List.prototype.remove = function(obj) { } }; -List.prototype.forEach = function(cb) { - this.items.forEach(cb); -}; - List.prototype.sort = function(cb) { return this.items.sort(cb); };