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

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.7 KB
Line 
1Object.defineProperty(exports, '__esModule', { value: true });
2
3var _getLength = require('./_getLength.js');
4var isFunction = require('./isFunction.js');
5var allKeys = require('./allKeys.js');
6
7// Since the regular `Object.prototype.toString` type tests don't work for
8// some types in IE 11, we use a fingerprinting heuristic instead, based
9// on the methods. It's not great, but it's the best we got.
10// The fingerprint method lists are defined below.
11function ie11fingerprint(methods) {
12 var length = _getLength(methods);
13 return function(obj) {
14 if (obj == null) return false;
15 // `Map`, `WeakMap` and `Set` have no enumerable keys.
16 var keys = allKeys(obj);
17 if (_getLength(keys)) return false;
18 for (var i = 0; i < length; i++) {
19 if (!isFunction(obj[methods[i]])) return false;
20 }
21 // If we are testing against `WeakMap`, we need to ensure that
22 // `obj` doesn't have a `forEach` method in order to distinguish
23 // it from a regular `Map`.
24 return methods !== weakMapMethods || !isFunction(obj[forEachName]);
25 };
26}
27
28// In the interest of compact minification, we write
29// each string in the fingerprints only once.
30var forEachName = 'forEach',
31 hasName = 'has',
32 commonInit = ['clear', 'delete'],
33 mapTail = ['get', hasName, 'set'];
34
35// `Map`, `WeakMap` and `Set` each have slightly different
36// combinations of the above sublists.
37var mapMethods = commonInit.concat(forEachName, mapTail),
38 weakMapMethods = commonInit.concat(mapTail),
39 setMethods = ['add'].concat(commonInit, forEachName, hasName);
40
41exports.ie11fingerprint = ie11fingerprint;
42exports.mapMethods = mapMethods;
43exports.setMethods = setMethods;
44exports.weakMapMethods = weakMapMethods;
Note: See TracBrowser for help on using the repository browser.