Explain the purpose of constructor() in Aurelia

 Posted by Rajnilari2015 on 8/24/2016 | Category: JavaScript Interview questions | Views: 2597 | Points: 40
Answer:

Constructor method is used for initializing object created with a class. This method is called first. If we don't specify this method, the default constructor will be used.
For example

export class App{  

constructor() {
this.counter = 1;
}
}


here we are initializing teh counter property to 1 inside the constructor. Later we can use this in the view and display the value as 1 like

<template>   

<p>${counter}</p>
</template>


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response