From a69e60b70f57977caf63df3dfac4369f27729d68 Mon Sep 17 00:00:00 2001 From: Tim-Smart Date: Fri, 17 Sep 2010 23:08:50 +1200 Subject: [PATCH] Fix queue::length and add forEach --- index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c692358a35..c6864b994a 100644 --- a/index.js +++ b/index.js @@ -255,13 +255,15 @@ Queue.prototype.push = function (item) { return this.tail.push(item); }; -Queue.prototype.length = function () { - return this.head.length - this.offset + this.tail.length; +Queue.prototype.forEach = function () { + var array = this.head.slice(this.offset); + array.push.apply(array, this.tail); + return array.forEach.apply(array, arguments); }; Object.defineProperty(Queue.prototype, 'length', { get: function () { - return this.array.length; + return this.head.length - this.offset + this.tail.length; } });