From 2319edf022ed8cfd30bff136328859a3660ba9da Mon Sep 17 00:00:00 2001 From: Kuitos Date: Fri, 9 Oct 2020 19:52:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20copy=20function=20prototype=20if?= =?UTF-8?q?=20it=20had=20while=20we=20create=20a=20new=20function=20using?= =?UTF-8?q?=20bind=20(#977)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sandbox/common.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sandbox/common.ts b/src/sandbox/common.ts index af34633..e05700c 100644 --- a/src/sandbox/common.ts +++ b/src/sandbox/common.ts @@ -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; }