From 37d9204ad93d83b941f82ba886268789298bbaff Mon Sep 17 00:00:00 2001 From: Timothy Jones Date: Wed, 20 Oct 2010 08:47:34 +1300 Subject: [PATCH] Tidying inArray utility. --- lib/nodes.js | 2 +- src/nodes.coffee | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index aaa61817..2c4a8df1 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1962,7 +1962,7 @@ UTILITIES = { "extends": 'function(child, parent) {\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype;\n child.prototype = new ctor;\n if (typeof parent.extended === "function") parent.extended(child);\n child.__super__ = parent.prototype;\n}', bind: 'function(func, context) {\n return function() { return func.apply(context, arguments); };\n}', - inArray: '(function() {\n var indexOf = Array.prototype.indexOf || function (item) {\n for (var i = this.length; i--;) if (this[i] === item) return i;\n return -1;\n }; return function(array, item) { return indexOf.call(array, item) > -1; };\n})();', + inArray: '(function() {\n var indexOf = Array.prototype.indexOf || function (item) {\n var i = this.length; while (i--) if (this[i] === item) return i;\n return -1;\n };\n return function(array, item) { return indexOf.call(array, item) > -1; };\n})();', hasProp: 'Object.prototype.hasOwnProperty', slice: 'Array.prototype.slice' }; diff --git a/src/nodes.coffee b/src/nodes.coffee index 740cc261..3b2038b5 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1675,9 +1675,10 @@ UTILITIES = inArray: ''' (function() { var indexOf = Array.prototype.indexOf || function (item) { - for (var i = this.length; i--;) if (this[i] === item) return i; + var i = this.length; while (i--) if (this[i] === item) return i; return -1; - }; return function(array, item) { return indexOf.call(array, item) > -1; }; + }; + return function(array, item) { return indexOf.call(array, item) > -1; }; })(); '''