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