inArray -> indexOf ...

This commit is contained in:
Jeremy Ashkenas
2010-10-19 23:06:51 -04:00
parent 35b6a70724
commit c1d24944dc
2 changed files with 19 additions and 13 deletions

View File

@@ -1480,7 +1480,14 @@
return "(" + (tests.join(' || ')) + ")";
};
In.prototype.compileLoopTest = function(o) {
return "" + (utility('inArray')) + "(" + (this.object.compile(o)) + ", " + (this.array.compile(o)) + ")";
var _ref2, obj1, obj2, prefix;
_ref2 = this.object.compileReference(merge(o, {
top: true
}), {
precompile: true
}), obj1 = _ref2[0], obj2 = _ref2[1];
prefix = obj1 !== obj2 ? ("" + obj1 + ", ") : '';
return "(" + prefix + (utility('indexOf')) + ".call(" + (this.array.compile(o)) + ", " + obj2 + ") >= 0)";
};
return In;
})();
@@ -1946,7 +1953,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 var i = this.length; while (i--) if (this[i] === item) return i;\n return -1;\n };\n return function(item, array) { return indexOf.call(array, item) > -1; };\n})()',
indexOf: 'Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) if (this[i] === item) return i;\n return -1;\n}',
hasProp: 'Object.prototype.hasOwnProperty',
slice: 'Array.prototype.slice'
};