回答編集履歴

1

追記しました。

2016/10/14 01:32

投稿

miyabi-sun
miyabi-sun

スコア21158

test CHANGED
@@ -11,3 +11,111 @@
11
11
  要約するとextends使うなってことですかね?
12
12
 
13
13
  「ExtendableBuiltin」を作るとかバッドノウハウ臭が凄まじいです…
14
+
15
+
16
+
17
+ ---
18
+
19
+
20
+
21
+ 当方LiveScriptに逃げた勢なので、ES6やBabelは疎いのですが、
22
+
23
+ LSでの解決策を見てみました。
24
+
25
+
26
+
27
+ ```LiveScript
28
+
29
+ class Hoge extends Error
30
+
31
+ name: -> 234
32
+
33
+ type: -> "Hoge"
34
+
35
+
36
+
37
+ a = new Hoge()
38
+
39
+
40
+
41
+ console.log(a instanceof Error) # true
42
+
43
+ console.log(a instanceof Hoge) # true
44
+
45
+ ```
46
+
47
+
48
+
49
+ こちらがコンパイル結果です。
50
+
51
+
52
+
53
+ ```JavaScript
54
+
55
+ var Hoge, a;
56
+
57
+ Hoge = (function(superclass){
58
+
59
+ var prototype = extend$((import$(Hoge, superclass).displayName = 'Hoge', Hoge), superclass).prototype, constructor = Hoge;
60
+
61
+ Hoge.prototype.name = function(){
62
+
63
+ return 234;
64
+
65
+ };
66
+
67
+ Hoge.prototype.type = function(){
68
+
69
+ return 'Hoge';
70
+
71
+ };
72
+
73
+ function Hoge(){
74
+
75
+ Hoge.superclass.apply(this, arguments);
76
+
77
+ }
78
+
79
+ return Hoge;
80
+
81
+ }(Error));
82
+
83
+ a = new Hoge();
84
+
85
+ console.log(a instanceof Error);
86
+
87
+ console.log(a instanceof Hoge);
88
+
89
+ function extend$(sub, sup){
90
+
91
+ function fun(){} fun.prototype = (sub.superclass = sup).prototype;
92
+
93
+ (sub.prototype = new fun).constructor = sub;
94
+
95
+ if (typeof sup.extended == 'function') sup.extended(sub);
96
+
97
+ return sub;
98
+
99
+ }
100
+
101
+ function import$(obj, src){
102
+
103
+ var own = {}.hasOwnProperty;
104
+
105
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
106
+
107
+ return obj;
108
+
109
+ }
110
+
111
+ ```
112
+
113
+
114
+
115
+ この概念を元にextendsを使わない自作Errorを生成して、
116
+
117
+ Errorを混ぜる関数を作れば良いのですが、これもバッドノウハウですね。
118
+
119
+
120
+
121
+ おとなしくnode-babelのサイトにissueを投げまくるしかないと思います。