Nodejs Array Each each(fun)

Here you can find the source of each(fun)

Method Source Code

/**/* w  w w.ja  v a2s  .c o  m*/
 * Created with JetBrains WebStorm.
 * User: mschwartz
 * Date: 12/24/12
 * Time: 2:59 PM
 *
 * GameEngine (C)2012-2013 Michael Schwartz. All rights reserved.
 */

function emptyFn() {}

function random(n) {
    return +n ? Math.floor(Math.random() * (n+1)) : Math.random();
}

Array.prototype.each = Object.prototype.each = Function.prototype.each = function(fun) {
    for (var key in this) {
        if (this.hasOwnProperty && this.hasOwnProperty(key)) {
            if (fun.call(this, this[key], key, this) === false) {
                return;
            }
        }
    }
};

Related

  1. each(fn)
    Array.prototype.each = function(fn){
        fn = fn || Function.K;
         var a = [];
         var args = Array.prototype.slice.call(arguments, 1);
         for(var i = 0; i < this.length; i++){
             var res = fn.apply(this,[this[i],i].concat(args));
             if(res != null) a.push(res);
         return a;
    ...
    
  2. each(fn)
    Array.prototype.each = function(fn) {
      for(var i = 0; i < this.length; i++) {
        fn(i, this[i]);
      };
    };
    
  3. each(fn, last)
    Array.prototype.each = function(fn, last) {
        if (typeof fn != "function") return false;
        for (var index = 0; index < this.length; index++) {
                fn(this[index], index);
        if (last) last();
    };
    
  4. each(fnCallback)
    Array.prototype.each = function(fnCallback) {
        var value = null;
        for (var elementIndex in this) {
            if (this.hasOwnProperty(elementIndex)) {
                value = fnCallback.apply(this[elementIndex], [elementIndex, value]);
        return (value) ? value : this;
    };
    ...
    
  5. each(fun)
    Array.prototype.each = function(fun) {
        for (var i = 0; i < this.length; i++) {
            fun(this[i]);
    };
    
  6. each(func)
    Array.prototype.each = function (func) {
        return _.each(this, func);
    };
    
  7. each(func)
    Array.prototype.each = function(func) {
      function each(array, func) {
      for (var i=0; i<array.length; ++i) {
        func.call(array[i], i);
     each(this, func); 
    };
    
  8. each(func)
    Array.prototype.each = function (func) {
      var arr = this;
      for (var i = 0; i < arr.length; i++) {
        func(arr[i]);
    
  9. each(func)
    Array.prototype.each = function(func) {
      for(var i = 0; i < this.length; i++)
        func(this[i]);