source: frontend/node_modules/underscore/cjs/_collectNonEnumProps.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1var _setup = require('./_setup.js');
2var isFunction = require('./isFunction.js');
3var _has = require('./_has.js');
4
5// Internal helper to create a simple lookup structure.
6// `collectNonEnumProps` used to depend on `_.contains`, but this led to
7// circular imports. `emulatedSet` is a one-off solution that only works for
8// arrays of strings.
9function emulatedSet(keys) {
10 var hash = {};
11 for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
12 return {
13 contains: function(key) { return hash[key] === true; },
14 push: function(key) {
15 hash[key] = true;
16 return keys.push(key);
17 }
18 };
19}
20
21// Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
22// be iterated by `for key in ...` and thus missed. Extends `keys` in place if
23// needed.
24function collectNonEnumProps(obj, keys) {
25 keys = emulatedSet(keys);
26 var nonEnumIdx = _setup.nonEnumerableProps.length;
27 var constructor = obj.constructor;
28 var proto = (isFunction(constructor) && constructor.prototype) || _setup.ObjProto;
29
30 // Constructor is a special case.
31 var prop = 'constructor';
32 if (_has(obj, prop) && !keys.contains(prop)) keys.push(prop);
33
34 while (nonEnumIdx--) {
35 prop = _setup.nonEnumerableProps[nonEnumIdx];
36 if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
37 keys.push(prop);
38 }
39 }
40}
41
42module.exports = collectNonEnumProps;
Note: See TracBrowser for help on using the repository browser.