ES6 and Typescript Tutorial - 22 - Class Body and Methods

preview_player
Показать описание

📱 Follow Codevolution

ES6 | ES2015 | Typescript | ES6 Tutorial | ES2015 Tutorial | Typescript Tutorial | ES6 Tutorial for Beginners | ES2015 Tutorial for Beginners | Typescript tutorial for Beginners
Рекомендации по теме
Комментарии
Автор

I saw in their site that the property needs to be declared first if you're going to initialize it inside the constructor.
like this:

class P{
name:string
constructor(name){
this.name = name;
}
}

And thank you for your tutorials sir. It helped me a lot. Im planning to watch your Angular2 Playlist too

ponssuarez
Автор

You should initiate the variable before using. Then do a getter for access it from outside

Maruf-ztdz
Автор

Try `constructor(public name: string)`

desprit
Автор

Shouldnt we declare name as a private variable before referencing it with the "this" keyword?

Ive learnt OOP in many languages (Python, C++ and PHP to name a few) and i thought Python was breaking conventions with the lack of private var declaration but i guess ES6 is on a whole other level xD

dimitarvel
Автор

name keyword is preserved by typescript and another is you need to initialize datatype for name variable before you direct assign any value

Typescript Code

class Person {





public fname: String;
constructor(myname:String){
this.fname = myname;

}


}

hirakumarmaharjan