|
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.3 KB
|
| Line | |
|---|
| 1 | import { nonEnumerableProps, ObjProto } from './_setup.js';
|
|---|
| 2 | import isFunction from './isFunction.js';
|
|---|
| 3 | import has from './_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.
|
|---|
| 9 | function 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.
|
|---|
| 24 | export default function collectNonEnumProps(obj, keys) {
|
|---|
| 25 | keys = emulatedSet(keys);
|
|---|
| 26 | var nonEnumIdx = nonEnumerableProps.length;
|
|---|
| 27 | var constructor = obj.constructor;
|
|---|
| 28 | var proto = (isFunction(constructor) && constructor.prototype) || 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 = nonEnumerableProps[nonEnumIdx];
|
|---|
| 36 | if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
|
|---|
| 37 | keys.push(prop);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.