Blame view

node_modules/es5-ext/object/_iterate.js 1016 Bytes
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  // Internal method, used by iteration functions.
  // Calls a function for each key-value pair found in object
  // Optionally takes compareFn to iterate object in specific order
  
  'use strict';
  
  var callable = require('./valid-callable')
    , value    = require('./valid-value')
  
    , bind = Function.prototype.bind, call = Function.prototype.call, keys = Object.keys
    , propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
  
  module.exports = function (method, defVal) {
  	return function (obj, cb/*, thisArg, compareFn*/) {
  		var list, thisArg = arguments[2], compareFn = arguments[3];
  		obj = Object(value(obj));
  		callable(cb);
  
  		list = keys(obj);
  		if (compareFn) {
  			list.sort((typeof compareFn === 'function') ? bind.call(compareFn, obj) : undefined);
  		}
  		if (typeof method !== 'function') method = list[method];
  		return call.call(method, list, function (key, index) {
  			if (!propertyIsEnumerable.call(obj, key)) return defVal;
  			return call.call(cb, thisArg, obj[key], key, obj, index);
  		});
  	};
  };