🐛 copy function prototype if it had while we create a new function using bind (#977)
This commit is contained in:
parent
0a0bdaa9be
commit
2319edf022
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user