🐛 copy function prototype if it had while we create a new function using bind (#977)

This commit is contained in:
Kuitos 2020-10-09 19:52:40 +08:00 committed by GitHub
parent 0a0bdaa9be
commit 2319edf022

View File

@ -28,6 +28,8 @@ export function getTargetValue(target: any, value: any): any {
const boundValue = value.bind(target);
// some callable function has custom fields, we need to copy the enumerable props to boundValue. such as moment function.
Object.keys(value).forEach(key => (boundValue[key] = value[key]));
// copy prototype, for performance reason, we use in operator to check rather than hasOwnProperty
if ('prototype' in value) boundValue.prototype = value.prototype;
Object.defineProperty(value, boundValueSymbol, { enumerable: false, value: boundValue });
return boundValue;
}