Simplify getFuncName.

This commit is contained in:
jdalton
2015-05-15 20:21:39 -07:00
parent 3490f8acb5
commit d6937baa8e

View File

@@ -1046,14 +1046,6 @@
*/ */
support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype'); support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
/**
* Detect if `Function#name` is supported (all but IE).
*
* @memberOf _.support
* @type boolean
*/
support.funcNames = typeof Function.name == 'string';
/** /**
* Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9). * Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9).
* *
@@ -4043,29 +4035,20 @@
* @param {Function} func The function to query. * @param {Function} func The function to query.
* @returns {string} Returns the function name. * @returns {string} Returns the function name.
*/ */
var getFuncName = (function() { function getFuncName(func) {
if (!support.funcNames) { var result = func.name,
return constant(''); array = realNames[result],
} length = array ? array.length : 0;
if (constant.name == 'constant') {
return baseProperty('name');
}
return function(func) {
var result = func.name,
array = realNames[result],
length = array ? array.length : 0;
while (length--) { while (length--) {
var data = array[length], var data = array[length],
otherFunc = data.func; otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
if (otherFunc == null || otherFunc == func) { return data.name;
return data.name;
}
} }
return result; }
}; return result;
}()); }
/** /**
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is * Gets the appropriate "indexOf" function. If the `_.indexOf` method is