Created
June 4, 2014 10:34
-
-
Save Williammer/b7ccaca6486ccac6d22d to your computer and use it in GitHub Desktop.
jsPatterns.revelation.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function () { | |
| var astr = "[object Array]", | |
| toString = Object.prototype.toString; | |
| function isArray(a) { | |
| return toString.call(a) === astr; | |
| } | |
| function indexOf(haystack, needle) { | |
| var i = 0, | |
| max = haystack.length; | |
| for (; i < max; i += 1) { | |
| if (haystack[i] === needle) { | |
| return i; | |
| } | |
| } | |
| return -1; | |
| } | |
| myarray = { | |
| isArray: isArray, | |
| indexOf: indexOf, | |
| inArray: indexOf | |
| }; | |
| }()); | |
| myarray.indexOf = null; | |
| alert(myarray.inArray(["a", "b", "z"], "z")); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment