Skip to content

Instantly share code, notes, and snippets.

@zhuangya
Created October 31, 2011 16:20
Show Gist options
  • Save zhuangya/1327877 to your computer and use it in GitHub Desktop.
Save zhuangya/1327877 to your computer and use it in GitHub Desktop.
indexOf prototype for IE 9-
/**
* Refs:
* http://nootn.com/blog/Develop/35/
* http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/#comment-57199
* http://ecma262-5.com/ELS5_HTML.htm#Section_15.4.4.14
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(el, index) {
var n = this.length >>> 0, i = ~~index;
if (i < 0 ) i += n;
for (; i < n; i++) if (i in this && this[i] === el) return i;
return -1;
}
}
@zhuangya
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment