Skip to content

Instantly share code, notes, and snippets.

@bignimbus
Last active August 29, 2015 14:08
Show Gist options
  • Save bignimbus/54aab5b806825d5feff8 to your computer and use it in GitHub Desktop.
Save bignimbus/54aab5b806825d5feff8 to your computer and use it in GitHub Desktop.
Simple version of Array.prototype.map
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