Last active
August 29, 2015 14:08
-
-
Save bignimbus/54aab5b806825d5feff8 to your computer and use it in GitHub Desktop.
Simple version of Array.prototype.map
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
Array.prototype.fakeMap = function (fn, context) { | |
var out = this instanceof Array ? [] : {}, | |
context = context || this, | |
result, | |
n; | |
if (typeof fn !== "function") { | |
return []; | |
} | |
for (n in this) { | |
if (this.hasOwnProperty(n)) { | |
result = fn.call(context, this[n]); | |
out[n] = result; | |
} | |
} | |
return out; | |
} | |
Object.prototype.fakeMap = Array.prototype.fakeMap; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment