MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / baseCreateCallback

Function baseCreateCallback

MathBox/mathbox-bundle.js:35997–36042  ·  view source on GitHub ↗

* The base implementation of `_.createCallback` without support for creating * "_.pluck" or "_.where" style callbacks. * * @private * @param {*} [func=identity] The value to convert to a callback. * @param {*} [thisArg] The `this` binding of the created callback. * @par

(func, thisArg, argCount)

Source from the content-addressed store, hash-verified

35995 * @returns {Function} Returns a callback function.
35996 */
35997 function baseCreateCallback(func, thisArg, argCount) {
35998 if (typeof func != 'function') {
35999 return identity;
36000 }
36001 // exit early for no `thisArg` or already bound by `Function#bind`
36002 if (typeof thisArg == 'undefined' || !('prototype' in func)) {
36003 return func;
36004 }
36005 var bindData = func.__bindData__;
36006 if (typeof bindData == 'undefined') {
36007 if (support.funcNames) {
36008 bindData = !func.name;
36009 }
36010 bindData = bindData || !support.funcDecomp;
36011 if (!bindData) {
36012 var source = fnToString.call(func);
36013 if (!support.funcNames) {
36014 bindData = !reFuncName.test(source);
36015 }
36016 if (!bindData) {
36017 // checks if `func` references the `this` keyword and stores the result
36018 bindData = reThis.test(source);
36019 setBindData(func, bindData);
36020 }
36021 }
36022 }
36023 // exit early if there are no `this` references or `func` is bound
36024 if (bindData === false || (bindData !== true && bindData[1] & 1)) {
36025 return func;
36026 }
36027 switch (argCount) {
36028 case 1: return function(value) {
36029 return func.call(thisArg, value);
36030 };
36031 case 2: return function(a, b) {
36032 return func.call(thisArg, a, b);
36033 };
36034 case 3: return function(value, index, collection) {
36035 return func.call(thisArg, value, index, collection);
36036 };
36037 case 4: return function(accumulator, value, index, collection) {
36038 return func.call(thisArg, accumulator, value, index, collection);
36039 };
36040 }
36041 return bind(func, thisArg);
36042 }
36043
36044 /**
36045 * The base implementation of `createWrapper` that creates the wrapper and

Callers 13

assignFunction · 0.85
cloneFunction · 0.85
cloneDeepFunction · 0.85
forInFunction · 0.85
forInRightFunction · 0.85
forOwnFunction · 0.85
forOwnRightFunction · 0.85
isEqualFunction · 0.85
mergeFunction · 0.85
forEachFunction · 0.85
forEachRightFunction · 0.85
createCallbackFunction · 0.85

Calls 1

bindFunction · 0.70

Tested by

no test coverage detected