mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Cleanup isLaziable and getFuncNames.
This commit is contained in:
@@ -3389,10 +3389,8 @@
|
|||||||
if (typeof func != 'function') {
|
if (typeof func != 'function') {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
var funcName = wrapper ? null : getFuncName(func);
|
var funcName = wrapper ? '' : getFuncName(func);
|
||||||
if (funcName && (funcName == 'wrapper' || isLaziable(func))) {
|
wrapper = funcName == 'wrapper' ? new LodashWrapper([]) : wrapper;
|
||||||
wrapper = new LodashWrapper([]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
index = wrapper ? -1 : length;
|
index = wrapper ? -1 : length;
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
@@ -4104,28 +4102,33 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var getFuncName = !support.funcNames ? constant('') : function(func) {
|
var getFuncName = (function() {
|
||||||
var result = func.name;
|
if (!support.funcNames) {
|
||||||
if (result) {
|
return constant('');
|
||||||
return realNames[result] || result;
|
|
||||||
}
|
}
|
||||||
var anons = realNames[result];
|
if (constant.name == 'constant') {
|
||||||
if (!anons) {
|
return baseProperty('name');
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
var length = anons.length;
|
return function(func) {
|
||||||
while (length--) {
|
var result = func.name,
|
||||||
var anon = anons[length];
|
array = realNames[result],
|
||||||
if (anon.func == func) {
|
length = array ? array.length : 0;
|
||||||
return anon.name;
|
|
||||||
|
while (length--) {
|
||||||
|
var data = array[length],
|
||||||
|
otherFunc = data.func;
|
||||||
|
|
||||||
|
if (otherFunc == null || otherFunc == func) {
|
||||||
|
return data.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return result;
|
||||||
return result;
|
};
|
||||||
};
|
}());
|
||||||
|
|
||||||
function isLaziable(func) {
|
function isLaziable(func) {
|
||||||
var funcName = getFuncName(func);
|
var funcName = getFuncName(func);
|
||||||
return funcName ? func === lodash[funcName] : false;
|
return !!funcName && func === lodash[funcName] && funcName in LazyWrapper.prototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11943,20 +11946,17 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (support.funcNames) {
|
// Map minified function names to their real names.
|
||||||
realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = 'wrapper';
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
||||||
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
var lodashFunc = lodash[methodName],
|
||||||
var lodashFunc = lodash[methodName],
|
key = lodashFunc.name,
|
||||||
key = lodashFunc.name;
|
names = realNames[key] || (realNames[key] = []);
|
||||||
|
|
||||||
|
names.push({ 'name': methodName, 'func': lodashFunc });
|
||||||
|
});
|
||||||
|
|
||||||
|
realNames[createHybridWrapper(null, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': null }];
|
||||||
|
|
||||||
if (key) {
|
|
||||||
realNames[key] = methodName;
|
|
||||||
} else {
|
|
||||||
var anons = realNames[key] || (realNames[key] = []);
|
|
||||||
anons.push({ 'name': methodName, 'func': lodashFunc });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Add functions to the lazy wrapper.
|
// Add functions to the lazy wrapper.
|
||||||
LazyWrapper.prototype.clone = lazyClone;
|
LazyWrapper.prototype.clone = lazyClone;
|
||||||
LazyWrapper.prototype.reverse = lazyReverse;
|
LazyWrapper.prototype.reverse = lazyReverse;
|
||||||
|
|||||||
Reference in New Issue
Block a user