Goal:
- Create object/methods to run the following in a closure/namespace:
- Collect data from a form.
- Exchange data with the server.
- Pass data received from server AND code from #1 to new objects/methods loaded after success of #3.
I thought that es6 classes might be perfect but ran into some issues, for example:
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
}
The obvious problem is instanceOfB.newVar === 'foo'
not bar
.
I have read quite a bit on this and cannot seem to make clear sense of how to best achieve the objective. I am 2 years slowly self taught so any help would be appreciated.