Rethink our indexOf implementation
This commit is contained in:
parent
99343e8fc0
commit
63f6f5f3c2
@ -111,15 +111,17 @@
|
|||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||||
|
|
||||||
Array.prototype.indexOf = function(val) {
|
Array.prototype.indexOf = function(val, i) {
|
||||||
var i;
|
var len;
|
||||||
i = this.length;
|
i || (i = 0);
|
||||||
while (i--) {
|
len = this.length;
|
||||||
|
while (i < len) {
|
||||||
if (this[i] === val) {
|
if (this[i] === val) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return i;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
__indexOf = [].indexOf;
|
__indexOf = [].indexOf;
|
||||||
|
|||||||
@ -89,15 +89,17 @@
|
|||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||||
|
|
||||||
Array.prototype.indexOf = function(val) {
|
Array.prototype.indexOf = function(val, i) {
|
||||||
var i;
|
var len;
|
||||||
i = this.length;
|
i || (i = 0);
|
||||||
while (i--) {
|
len = this.length;
|
||||||
|
while (i < len) {
|
||||||
if (this[i] === val) {
|
if (this[i] === val) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return i;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
__indexOf = [].indexOf;
|
__indexOf = [].indexOf;
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
# I am bad at JavaScript and if you reuse this, so are you.
|
# I am bad at JavaScript and if you reuse this, so are you.
|
||||||
Array::indexOf = (val) ->
|
Array::indexOf = (val, i) ->
|
||||||
i = @length
|
i or= 0
|
||||||
while i--
|
len = @length
|
||||||
|
while i < len
|
||||||
return i if @[i] is val
|
return i if @[i] is val
|
||||||
return i
|
i++
|
||||||
|
return -1
|
||||||
|
|
||||||
# Update CoffeeScript's reference to [].indexOf
|
# Update CoffeeScript's reference to [].indexOf
|
||||||
# Reserved keywords are ignored in embedded javascript.
|
# Reserved keywords are ignored in embedded javascript.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user