-1

I am trying to access my property defined in a class constructor, from a method but it comes as undefined. Following is my code.

export class App {
  uri:string
  constructor() {
    this.uri = "bbc"
  }

  public address(){
        $( "#post" ).fadeOut( "slow", function() {
            window.location.href = window.location.protocol + "//" + window.location.host + this.uri +".com"; 

        });

  }
}

and here is plunker example. The question was marked as duplicate but it is not, as I am inside class and I cannot use arrow function, as far as I am aware

localhost
  • 822
  • 2
  • 20
  • 51
  • That doesn't look like ES6. Is it TypeScript? The capitalisation of `class` and `Purchasing` seems off, and the `newUrl` type declaration should probably go inside the class body. – Bergi Aug 21 '17 at 13:26
  • @Bergi Yes it is TS. updated the question and code.Sorry for typos first as I am new to the language. – localhost Aug 28 '17 at 23:11
  • 1
    @Nofel Still a duplicate though. I've added a link to a TS-specific question in the notice that appears at the top of your question. I've left Bergi's link there because the methods you can use for JS also apply to TS. – Louis Aug 28 '17 at 23:17

1 Answers1

0

try to insert this inside the constructor:

this.newUrl = this.newUrl.bind(this);
Yuri Pereira
  • 1,945
  • 17
  • 24