1
我想在原生JS中擴展數組。但不只是修改原型。我想我會用新的class
es2015語法來嘗試一下。巴貝爾不能正確地擴展數組?
嘗試它本地(鉻已支持它 - yayヽ('▽`)ノ),它的一切正常工作。切換到巴貝爾更好的支持,它停止工作。嘗試了一下之後,我看到,新對象中沒有任何方法可用。測試代碼:
class CustomList extends Array {
constructor(...elms) {
super(...elms);
this.testprop = "test";
}
customMethod(a) {
console.log(a, this);
}
}
見https://babeljs.io/docs/usage/caveats/#classes – undefined
@ unlucky13好像我有點...不吉利? 感謝您的評論。這看起來就是這樣。心中加入它作爲一個aswer,所以我可以接受它?謝謝」 –