###問題点
node-babel で instanceof が思った通りの結果を返しません。自分が作成したクラスのインスンタンスを new して直後に instanceof で聞くと、 false が返ります。なぜ、true にならないのかわかりません。以下のソースコードとおり、クラスのインスタンスを作成し instanceof で問い合わせると、なぜか false がかえります。
どうも、 Error クラスから extends しているのがだめなようですが、理由がわかりません。
また、いろいろ回避策は考えられますが、スマートな回避策があれば、ご教示ください。
Javascript
1class LogicError extends Error { 2 constructor(message) { 3 super(message); 4 } 5} 6let le = new LogicError('Some Error.'); 7console.log(le instanceof LogicError); // なぜ false? 8console.log(le instanceof Error); // true 9
実行結果は以下の通り。
$ ./node_modules/babel-cli/bin/babel-node.js test.js --presets es2015,stage-0 false true
###環境
macOS Sierra 10.12
node.js v4.5.0
node_modules
├── babel-cli@6.16.0
├── babel-core@6.17.0
├── babel-preset-es2015@6.16.0
└── babel-preset-stage-0@6.16.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/13 09:13
2016/10/14 05:13
2016/10/14 06:05