each.js

From disqus.com, 7 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to array/some.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/24b64843 Embed
Download Paste or View Raw
  1. define('core/utils/collection/each',[
  2.     'core/utils/object/has',
  3. ], function (
  4.     has
  5. ) {
  6.     'use strict';
  7.  
  8.     /*
  9.      * Iterates over an object or a collection and calls a callback
  10.      * function with each item as a parameter.
  11.      */
  12.     return function each(collection, callback) {
  13.         var length = collection.length;
  14.         var forEach = Array.prototype.forEach;
  15.  
  16.         if (isNaN(length)) {
  17.             // Treat collection as an object
  18.             for (var key in collection) {
  19.                 if (has(collection, key))
  20.                     callback(collection[key], key, collection);
  21.             }
  22.         } else if (forEach) {
  23.             // Treat collection as an array
  24.             forEach.call(collection, callback);
  25.         } else {
  26.             for (var i = 0; i < length; i++)
  27.                 callback(collection[i], i, collection);
  28.         }
  29.     };
  30. });
  31. // https://c.disquscdn.com/next/next-core/core/utils/collection/each.js
  32. // https://a.disquscdn.com/next/next-core/core/utils/collection/each.js

Replies to each.js rss

Title Name Language When
debounce.js disqus.com javascript 7 Months ago.

Reply to "each.js"

Here you can reply to the paste above