-
-
Save brettz9/6367524 to your computer and use it in GitHub Desktop.
This file contains 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
var each = function (Array) {"use strict"; | |
/*! all you need to `each(obj, cb [,context])` | |
* @author WebReflection | |
* @license WTFPL - http://en.wikipedia.org/wiki/WTFPL | |
* @gist https://gist.github.com/2294934 | |
*/ | |
var | |
toString = {}.toString, | |
hasOwnProperty = {}.hasOwnProperty, | |
array = toString.call([]), | |
NL = typeof NodeList != "undefined" ? NodeList : Array, | |
isArrayLike = function isArrayLike(obj) { | |
return obj != null && | |
( | |
obj instanceof Array || | |
obj instanceof NL | |
) || | |
toString.call(obj) == array || | |
( | |
( | |
(t = typeof obj) != "function" && | |
t != "string" | |
) && | |
typeof(l = obj.length) == "number" && | |
l === ~~l | |
) | |
; | |
}, | |
forEach = [].forEach || function forEach(callback, context) { | |
for (var | |
obj = this, i = 0, length = obj.length; | |
i < length; | |
++i | |
) | |
i in obj && callback.call(context, obj[i], i, obj) | |
; | |
}, | |
t, l | |
; | |
return function each(obj, callback, context) { | |
if (isArrayLike(obj)) | |
forEach.call(obj, callback, context) | |
; | |
else for (var key in obj) | |
hasOwnProperty.call(obj, key) && callback.call(context, obj[key], key, obj) | |
; | |
}; | |
}(Array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would probably use
Object.entries(...).forEach
now