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