From cdb0e47202551ce43ffd4c52433c2c57c6c7f45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B8=86?= Date: Tue, 2 Jul 2019 15:57:52 +0800 Subject: [PATCH] fix the non-enumerable of the class prototype --- pages/Advanced Types.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/Advanced Types.md b/pages/Advanced Types.md index 4a5ffd451..70171c94b 100644 --- a/pages/Advanced Types.md +++ b/pages/Advanced Types.md @@ -10,18 +10,18 @@ You will mostly see intersection types used for mixins and other concepts that d Here's a simple example that shows how to create a mixin: ```ts -function extend(first: First, second: Second): First & Second { +function extend(first: First, second: Second): First & Second { const result: Partial = {}; for (const prop in first) { if (first.hasOwnProperty(prop)) { (result as First)[prop] = first[prop]; } } - for (const prop in second) { - if (second.hasOwnProperty(prop)) { - (result as Second)[prop] = second[prop]; + Object.getOwnPropertyNames(second).forEach(prop => { + if (prop !== 'constructor' && prop in second) { + (result as any)[prop] = (second as any)[prop] } - } + }) return result as First & Second; }