Transcript for:
Lecture on JavaScript Classes and Constructors

so okay which me it's a constructive function okay we are passing two arguments name and AG okay this property we property second we have something called method we call meod it's basically an action Okay so called greet and save this okay let save this inv person one person 2 having same function but person one it is again copying the instance this function okay so it's a bad practice so just and okay super let's save this let's save this so which means okay but trust me when you are coding some big applications it will make a sense okay so make okay one okay second okay fine right but what supp cannot read property of undef read okay you have to use new okay will rece some random like this okay will have a new property inside the this function block okay it's called new. Target this target want to declare an error so using soow new error I can have some message like function must be called with new keyword okay before let's save this and so let this function must be called with a new keyword okay save this and okay so Javas BL blueprint for creating objects which will have sh properties and methods okaya C++ samey okay fine simple CL okay and just block when we want to some values okay it's called constr Constructor we can pass some arguments so for example name and AG so name okay that's all simple okay so you have to call the class using new keybord so new and person we are having name and age so the name and it's coming from thisr and because I want to implement the same logic okay so let's cons cons invited guest one okay let's save this and check so lock let's lock invited guest inv guest one let's save this so function function that's all okay let's save this we will have something called okay okay [Music] save this okay new invited guest toass okay so and 41 okay let's save this okay let's save this and class Constructor person cannot be invoked without a new differ okay so what are the problems in function Constructor so syx and readability so first will have morees okay let's say 50 lines of codes 100 and even 400 okay we no in checks for we have to Define it okay and sharing methods are little difficult make some mistakes so we are humans right humans always make mistakes okay okay I will put it as a comment so buin check for what super in Constructors and next thing main okay okay try to create class we have something called function declaration named functions function so for we can have anything for example human it is like saving a variable can have anything like for example name this newy so new and human for example so cons and human so let's log the human here human let's save this okay save this okay let's save this class the CL expression okay example human in okay let's save this okay so we called class expression okay so that's what we call as anous CL creating classes so function construct okay so learner okay fine so okay fine have to have three properties name AG Prof Prof whatever okay learner damic values okay Constructor to have name H and profession so profession type okay profession this profession let's save this I want to I want to simple bio so hello my name is so this. name and I am this. H years old and my profession is profession okay let save this and that's what we call as class okay so learner a class okay so new key it's a good sign so new learner I'm getting name age and profession name H profession software developer developer okay so I used to call me myself engineer okay let save this so cons and learner one okay let's loog this Le one let's save this so it's calledo save thiso my name is my okay okay whenever you are having a new class new okay the same let's cre it in class expression learner okay save this refresh and it's working perfectly okay so that's why we call class expression okay so thir it's called class anonymous anonymous class okay let's save this some people will ask such kind of questions how many typ of I'm so happy to see your response we have something called gets and sets number is okay so get typ class declaration learner okay let's save this save this okay super so what we will have age name profession it's called property so Lear one name let's save this refresh I want to like we can use something called gets okay so gets number okay okay we can create something called get okay so name okay you will have many hel methods this okay let's save this and because Le one name it will be like lock learner one dot have something called full name [Music] full name save this let's save this let's save this and cannot say property name of learner which has only so Lear one what we we call as get set the learner one do name okay okay so let save this get set and name save this maximum call property values so which means okay like so this this okay so practice let this put something and false Le one save this set so type off type off value should be should be set the of to this value okay let's save this I have to use the so H I want to return this. h save this so let's save this Maxim it's because of using the public name save this and refresh and save this sa this example save this okay so regarding the property visibility so public private okay super for example oration for example okay modifier can only be used in typescript files so class member cannot have the key okay okay so local that's what we call as class field function okay that's a reality going right track so all the very best bye [Music]