typescript - Undefined with class implementing abstract class -


i'm not expert in javascript, , i'm conscious issue follow typescript code starts there. i'm stuck here in last 36 hours, in typescript i'm having undefined issues , let code explain rest:

window.onload = () => { var = new ipropindex(new ipropservice()); };  interface iidocservice<t> {     getsingle(): ipropdoc; }  class ipropservice implements iidocservice<t> {     getsingle(): ipropdoc { return new ipropdoc(); } }  abstract class idocindex<t> {     constructor(public _idoctype: string, public _iidocservice: iidocservice<t>) {         console.log(this._idoctype); //not undefined         this.methodb();     }      public abstract methoda();      public methodb() {         this.methoda(this.methodc); //**undefined**     }      public methodc() {         console.log(this._idoctype);     } }  class ipropindex extends idocindex<ipropdoc> {     constructor(public _ipropservice: ipropservice) {         super('iprop', _ipropservice);         console.log(this._ipropservice); //not undefined     }      public methoda(callback: any): void {         console.log(this._ipropservice); //**undefined**         callback();     } }  class ipropdoc { public name: string; } 

how can have solution without having undefined issues signed in code!? thanks.

console.log(this._ipropservice); //undefined

you have wrong this.

fix

use arrow

public methoda = (callback: any) => {     console.log(this._ipropservice); //**undefined**     callback(); } 

more : https://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -