目标:
我认为es6类可能是完美的,但遇到了一些问题,例如:
class A {
constructor(){
this.myVar = 'foo';
}
dataXchange(data) {
//send to server
//set response:
this.myVar = 'bar'; //serverData
$(el).load(html); // this page includes script with class B
}
otherMethod () {}
}
//////////////////////
class B extends A {
constructor(myVar, otherMethod) {
super(myVar, otherMethod);
this.newVar = myVar;
}
// Do more stuff here or use otherMethod
}
明显的问题是instanceOfB.newVar === 'foo'
而非bar
。
我已经阅读了相当多的内容,似乎无法清楚地了解如何最好地实现目标。我慢慢自学2年,所以任何帮助都会受到赞赏。