Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function each(array, fn, oThis) {
- 'use strict';
- var name, i, len = array.length,
- hasOwnProperty = Object.prototype.hasOwnProperty;
- oThis = oThis || array;
- if ( hasOwnProperty.call(array, 'length') && hasOwnProperty.call(array, '0') ) {
- // if it's array-like, iterate through its numerical keys
- for (i = 0; i < len; i += 1) {
- if (fn.call(oThis, array[i], i, array) === 'stop') {
- break;
- }
- }
- } else if (typeof array === 'object') {
- for (name in array) {
- if ( hasOwnProperty.call(array, name) ) {
- if (fn.call(oThis, array[name], name, array) === 'stop') {
- break; // 2 if statements for readability
- }
- }
- }
- }
- return array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement