Transcript for:
Understanding JavaScript Closures and Inheritance

the recording good morning everyone so let's start today okay so let me share this screen okay let me know if you guys can see the screen Pisha nin okay okay yep good morning everyone good morning goami good morning baneswar yeah so let's start okay so where we were today is day 2 we are we were basically on the last working day we were uh the last day we were you know studying JavaScript we were talking about closures right so the concept of closure so let's start from there the remaining part so what we can do we can just start you know I told you there is an example which is which I want to show you guys so will start from there itself so there we have let's see not. txt and script.js okay we don't need to can can just have an index. HTML okay closures continued so what did we understand from the closure you know we were seeing the examples you know like we saw the example of Grandfather you know the father and an example the function that returns another function grandfather function you know console logs something maybe rainning a function which is having you know a variable of father and also utilizing CR we and similarly we saw this other function is returning a sun function for example and Sun function is utilizing all the three variables even though the upper functions go out of the scope or memory you know out of the memory still we are able to utilize the aable in the functions which are using this is known as closure the function is supposed to have a which is using a variable from lexical scope for any scope above it so this is known as closure and we have seen that with example you know properly okay okay yeah so let me show you some examples over here so we saw it's very useful feature of JavaScript and very very important feature feature and without it many of the programming is not possible in uh you know JavaScript the the powers of JavaScript is one of the strength is closures you know and this is such an important feature after it got popularized by JavaScript it was adopted in many other programming languages so let let me just show you the impact of JavaScript in terms of memory so so let me just take you to this JavaScript file an example of memory we are going to see so suppose uh generally suppose we have uh we are creating a function which is a functionality to provide certain employee so let's do that generally what we see Suppose there is a function which is taking an employee ID and it is you know maintaining certain database employee database maybe it is an array of say 100,000. build with employ whatever okay so what it is we are doing we are saying okay okay and it is going to basically return the employee for example just a sudo code just to understand what's going on let me just take it to browser okay can you see the browser arami do we have AR today Che okay everyone is able to see yeah okay so what is happening over here what we can see okay we call get employee and say give me 100th employee so it is giving me 100 employees giving me 10th employee it is giving me 10th employee may give me ninth employees it is able to get but you see whenever I'm calling this it is again and again you know telling me that the database created so this function is not yet optimized from memory perspective so how do we optimize this we need to basic basically separate out this thing which is not required when I'm getting the employe so separation of the functionality we are going to do that let's see what we can do over here so Suppose there is a uh not very optimized we get employee 100 get employee 200 get employee 300 the Cod is not optimised and efficient from memory perspective so let's do that let us do it let us do it how do we do that we create a function and you know I'm I'm showing you the from the perspective of closures okay yeah I'm audible properly now everyone just anybody can tell me it's okay Sita okay thanks yeah okay so yeah uh create employee database for example this is the function which is going to create an employee database for example I create the database employee data base equal to blank by default and then what I can do emplo database dot equal to new if it is empty ideally we should check if not employee database it's going to check the piness and employee or employee either it is not there or employ database do length to equal to 1 then what we can do we can say create the employ database equal to new array 100,000 just it's just a sudo thing there is no reality just want to from illustration perspective we are you know just assuming there is a database creation step and then what we want we want to create another function get employee get employee closur exam closer get employee closure okay it's an example of closure let me just remove from the name that employee optimize what is going to take it's going to take the employee ID and what it is going to say okay if employee ID is greater than than equal to zero and employee database exist and employee database do length exist then come over here return the employee okay emplo do ID yes return it what is the employee employee ID employe database of employee ID is employee ID okay so what we are going to do database created you need to inform that database created and created employe database okay let's just copy this see that in action what we want to do we want to First create an database but suppose somebody else call called it optimized Wasing in some employee it's not going to return any anything because we have you know made our code robust enough to understand and all the necessary checks are there so it's not going to give you anything to the user of course but it's also not going to get you know broken because of the execution so first we need to create the database so we have created the database so what is the employee database let's check it is still empty what have we done let us check to equal to zero this was the mistake the lens should be if it is zero and not having zero means not having any any any member or what we are saying we are saying employee database doesn't exist either it doesn't exist having a false you know falsy value with this or or operator is is basically either this is true or this is true either of if this is true it will go inside if it is false for example this exist in our case this is going to be false mean actually it exists and but then it is going to check the new the next condition which is employ database. length if it is zero then it will come over here the logic was wrong I by mistake return one so let me save it let's create the database first okay employee database created look at that and then we can get employee get employee optimize which employee we want we a 90th employee we can give so it is able to give me and you say okay give me 9900 employee it is giving me giv 9,000 employ is giving what it is do it is actually G you know uh giving me what is required it is giving me the employee but it is not creating the database so this is much optimized code than what we have written earlier right how this is an example of closure can you see this function has nothing to do with this function okay an employee database is a variable in a global scope so what is the lexical scope of get employee optimized what is the lexical scope of G employee optimize anybody can tell Mei arita naena Global correct AR Global is the emplo is the scope of lexical scope of get employee optimized right and this V this variable employee of database is in the global scope so ideally when we execute this function you know things doesn't things are not available but Global scope is a lexical scope this this function is having closure over here even if even if this was not even if this was not uh in the global scope suppose let's let us modify this function to even have a better understanding of what I'm saying suppose just a second okay uh suppose instead of this uh let's say we have optimized two or optimized one in which we have database here itself okay instead of this we call it get optimize and have it like this instead of we are having like this and what we can do we can return a function like this to have to see that in action even that was a example of closure but it will be exercised here you will see that in action okay create employee database and then I have returned this function okay so how do we use this let us go into the BR let's say get employee get employee okay equal to create employee database employee database created now I can get the employee get employee employee 100 100 what is returning what is this employee ID who I have not paed what to this okay what is the mistake in somebody please explain anybody quickly what is the mistake here you know uh I'm when I'm calling get employee which is the function written by this this function what is the mistake here why it is giving me no returning undefined and somebody tell me it's not returning anything when it goes undefined function name function name no where function name not given here here no that's not needed because that that could be this is anonymous function you know but we can we respect you whether function name you give or not it doesn't matter somia is right the employee ID is basically is is the function itself is not taking any parameter but we are expecting that function to take a parameter and it should not it should take a parameter that's a mistake okay and so it should take an employee ID so let us just PST it [Music] now okay database created get employee it is going to return me a function still it is still it is not working what is wrong something is wrong here yes you know what has happened can anybody tell me quickly harita gami Som what is wrong over here ideally I think we have written everything fine but there is one mistake again can you see mistake is the spelling is wrong you know this should be like this the employee and this is there is a difference between this that's why it's not able to detect it can you see everyone n Trisha Mahendra everyone there is a spelling mistake over here see that [Music] employee spelling wrong is here in this so I fixed it all three places I could have done it otherwise but semantically this is better again I can see again I can say get employee get employee 100 now it is working right everyone s anilam it's for everyone Trisha okay so if I say10 it's giving me but it's not again and again creating the database you know in both the functions there there was closure in this function as well and in this function as well but in this function since we know Global scope always exists so in this function you know we are not able to see it in a much better way that it is getting exercised but in this one we can see that when this function goes out of scope as soon as we call it this function create employ database go goes out of a scope once the calling is over it will go out of the scope means it it it is it is popped out out of this deck from the memory and then what it is doing it is returning a function again so it is so ideally employ database should not exist so as a lexical uh environment will go out of the scope but it creates a closure we have seen for example uh example if we just in this example if we just say debugger and hit enter okay so as soon as we call it can you see that there is a closure here closure of this closure of this created by this whatever the anonymous function is WR when this function is invoked we have invoke get employee with the ID 110 right when this got invoked so whenever a function inves you remember execution context get created and you know all those things remember that so it goes through two steps declaration phase and real execution phase in declaration phase itself you know it is it was the compiler came to know that this function is having a closure over this variable so it created whenever this is going to be get created or executed it will create a closure for the closure of this lexical scope for this so it creates a closure wherever the closure it is set to get this function is having closure over this even if this function goes out of scope database it will keep working because a closure will be created out of it so this is a closure employ database entire database is available this variable is available so can you see that exercise everyone grami sh everyone okay chandu naita rishita pavitra naen VI Mahendra jtd Som Ganesh so you are able to see closure in action okay please you know it is all it is good for you to interact with okay you know if you doing something else it's of no use right please don't waste your time guys please focus on what I'm teaching you and it is going to be very very helpful for you I'm telling you on once you start you know self study on this it's going to help you it is for you so just humble request to everyone okay so let's move ahead you guys saw that example right so let me move again and then we have come over here so you have seen the example of memory so there is another you know implication or you know I would say the application of this thing the closure is encapsulation so we'll see that in action now what is encapsulation encapsulation is one of the principles of course this is going to be see that in is one of the principles of object orientation but it's like enclosing or putting what is uh required by a unit with the unit itself not outside is en caps solution you're not going to show that everywhere else right so what is the use of do fill okay there are many things you know thought fill is nothing don't focus on this this is not the area of focus there will be many things which teacher uses you know I don't want you to focus on this because I consider this is one of the database but to understand you know just to create the illustration I did this this is one of the methods of provided by the AR function fun array is one of the function Constructor Constructor function sorry one of the Constructor function we will see that you know see Phil is basically what it created Created 100,000 array array of 100,000 you know just simulating the database it doesn't matter are you able to get an are you able to get the closure that's what matters this is what I am teaching this is not I'm teaching right now this is not an area of focus area of this you can get hundreds of you know things from everywhere but there are few things which you can miss right now but Concepts you cannot miss right this is very important you need to focus on what I am I want you to focus on but understand this is a method provided by Constructor function just and it is it is immaterial right now what it is just we are creating a simulation of a database which is of course a bad example here but just understand we don't need database here just wanted to run this function by n number of times that's that's why I created it this is not the area of focus area of focus was memory optimization means it is basically not creating this again and again see in the example the idea is to not create the database again and again the database got created just once and we can just use it the way we want can you see Anita can you see that look at the it is only giving me the employee but with the help of closure functionality or the concept of JavaScript it is able to give me that and which is going which is helping us in the memory but this is not area of Focus right now area of focus is how we improved it doesn't matter whether it's fill or unfill or whatever it doesn't matter such fun functions you can learn you know as you as you will study as you will write programs and work in a project such thing you will that will come to you that's very very small thing having an array having 30 function or 50 function I teaching all 30 function doesn't make sense two three or five important things are good for you but you will explore as you go ahead okay important concepts are important that's why I'm teaching closure you know this is what is what what is important for you is to understand the concept I'm not showing here I'm not showing here you know uh what we can say uh the these things I'm showing here the functionality how closure is getting exercised okay you get it you get it an you're fine right Phill is just one function provided by ARR doesn't matter right now closure is the concept you should get it okay let's move ahead everybody got the me how memory was you know how the memory was you know know saved by this function we only created this once and we can call it 100 100 times doesn't matter 200 times 100,000 times it doesn't matter but this got created on device but with the help of which functionality which feature of JavaScript closure you get it everyone this is for everyone right TI goami supria Som naen yeahum shik okay good Saba Madu yes okay so let's move ahead let me show you another example where I am okay so this is our Javascript file okay let's move ahead and let's see the example of encapsu solution so let's get a very relevant functionality over here and I will call it uh daily routine why I called it daily routine you will know that soon okay so what we are going to do over here the problem statement is problem statement is say problem statement is what what we want to do we want to do and we want to monitor self study and want to monitor self study and expose results and and time which is Gone without self study we want to monitor self study and expose results and time which is Gone without selfstudy and benefits of output will be output or result will be benefits of selfstudy benefits suppose this is a PA problem statement we want to do something which can help us to self study in a much better way suppose and also track time so say our daily routine we have this variable let for example elapsed time oh my God elapsed time and let us initialize that with zero we have this elapsed time and what we want to do we want to have a function which is going to take time it's going to increase the time by say 1 second one it is going to increase the time by one left time equal to left time + one and also going to uh show the same information onto the screen or console in this case and this is not possible without something which basically increases the time so set interval is one of those methods which provides us timer to run something periodically so set interval if you go to the definition set interval is it takes a Handler and takes a time out in numbers and any number of arguments this arguments goes to this function but we are not going to pass the argument we don't need that those are optional as well time out is also optional but we are going to use that so Handler we are going to pass and we are going to pass we are going to uh you know invoke it every 1,000 milliseconds so this time is in Mill seconds so I had gone on to the definition of that value so what will I will give I will say okay take time keeping working it every th000 milliseconds this is in milliseconds okay one one second is having how many milliseconds 1,000 milliseconds okay so this is this this is an API set interval set time out all these are we have a PS product provided you know to us from the from the javascri but it is not ex not executed by JavaScript it is executed by by JavaScript run time it is it executes outside it means means there is a monitoring system which basically takes the code and you know executes in a different mechanism once the JavaScript is done with its uh the current work it is going to get executed later so take time just remember it's it's a watch which is basically ticking every second like this we are not going to focus on this this is not our Focus just a watch which is a timer is created that's it and what we want to do we want to do self study what is what how we are going to do self study as soon as whenever we study we say okay lefts time should reduce to zero again time should reduce to zero as soon as we do self study time will reduce to zero and we also want to um have something which is going to tell us time without self study time time without self study okay so what it is going to do is going to just return uh time without self study is okay and this daily routine function is going to return object and we are going to have for example the return this object self study property which is assigned to self study get time without self study is we are going to assign it to a function not calling it just assigning so reference is going to get passed to this one okay okay so let's see if this working we'll what we'll [Music] do we'll just go to our HTML and include this script over here script.js okay but we have not invoked our function so let us if we have this C cell study monitoring tool we have created self study monitor equal to daily routine uh we don't have it where it is able to call this daily rtin okay we have not started our own server so let's create a variable which is our self study time monitoring tool to to basically monitor our daily routine and it should create a timer and return an object and EPS is not aun not defined okay there is some spelling mistake I think elapsed where elaps 54 why it is isue okay we are not interested in this function just create a self monitor it should every SEC every you telling us how much time is passed without selfstudy so now let's do selfstudy self study monitor do selfstudy as soon as we do self study it say reset time okay you just now have self study okay and we says uh shelf study monitor study monitor do time without get time without self study it's 16 get time without self study is 17 get time without self study 21 you know but as soon as we do self study it's going to get re going to take time without selfstudy time without self study are you getting but now but this is not right right because you know we our self study is being controlled by outside environment you know it is rning self study ideally it should not your self study should be dependent on you guys you know when you are doing self study when har is is doing self study should be controlling the self study not the people around not the relatives not the friends and everybody right you should be telling yourself what is important to you and you should decide it on yourself exposing self study is not right exposing time without self study is okay everybody will come to know that you are not studed you are engaged to other activities but this is not something which we want so you will remove it you know and what you will do what you will do you will have let me just do self study it should automatically we should automatically have uh for example in you we should decide automatic study should be happening every day so what you can do you should automatically do that how we can do that like this so if in the tick time every tick time you are going to sell study so whenever elaps time you say elapsed time is greater than zero and of course elapse time is divided by or 5 equal to equal to zero what does this do this is a mod modulus operator we have learned that in operators remember what it do it does give us the reminder when it is completely divisible by five the remainder is zero so if the remainder of this expression is zero modulus operator remember modulus operator guys yeah yes so else time greater than what we are going to do we are going to do self study okay it should automatically help have happen every uh you know every the fifth the fifth tick it's going to happen so let's see if it is happening as soon as sorry we say self study monitor delor it should automatically start the timer and as soon as it reaches you know five fifth ticket should automatically look at that it is reset it after five means this is a time without self study time without self study is two time without self study is four time without self study five time without self study two it means you are doing automatic self study every day you are doing it that's why it's coming but we are not able to monitor the performance for example so let's say there is one more variable uh confidence level is at zero by default but whenever we do self study our confidence level should increase do you remember this operator this is known as who is going to tell first which operator is this this Plus+ which operator is this forgot increment correct n this is an increment operator so automatic self study but we also want to allow this to be available to the outside world so get confidence level confidence level and you are going to give this variable [Music] confidence variable over here which is which is not a function which is a variable we are giving so it should automatically in increase the confidence uh whenever you do self study let's see time without self study one time without self study two as soon as you study okay automatically you have studied so get confidence level your confidence level right now is at zero okay let just create a function to return this function get confidence LEL just return return confidence l and give this function over here okay confidence level it is what should increase ideally and then let's see if it works is at zero right now look at that confidence level has come to one confidence level is increasing and if we say get time without self study three and again you are studying as soon as you know 50 happen your confidence level is increasing time without self study you just not studied two three tis back and your confidence level has reached to five so are you getting you know what I'm displaying this this is how you you relate the real world problem you want to you know have a fun program or software on on your monitoring your daily routine you know all these things but why we have not exposed selfstudy otherwise self study will be in the control of outside world which is a user of this function which means your self study if you you know come back to the real world problem suppose if I have to study my study should not be dependent on outside world right outside world is saying this outside world will say self do self study outside world should not be controlling my study right I should be controlling my self study so this is not supposed to be exposed this is how you hide you know what is not supposed to be exposed and this is one of the parts of encapsulation Auto you know are you getting we are not we are encapsulating everything or and exposing what is only required to be exposed okay there are many principles are getting applied here we are going to talk about it soon okay Nish nin everyone arita gami okay SI okay Saba you getting it okay so let's move ahead chandu pu pushpa shabin yes yes okay good Rish is also saying yes we don't have any doubts here right we are going to move on to the new topic rest of the people okay Nara pavitra Satya Supra Sai Lisha you guys okay Shri tari jtd you guys are not talking anyway okay said yes she's fine so let me move to the new topic now we have studied closures closures completes over here properly I am hopeful that you guys are aware of closures now so uh next create another folder over here prototypes another very very important topic so prototypes prototypes okay or prototypal inheritance prototypal inheritance what is what am I talking about here what is prototype of inheritance first you need to know what is inheritance so inheritance is a way in terms of programming is a way to be able to use the properties of another object in relation okay there should be a relation between that and we should be able to use the properties me data and variable data variable and F functions of other objects so this is what we generally it is basically mapping to the same concept of our daily life you know routine as our society that we inherit you know few things from our parent and those from their parent and then per even 100 Generations back 200 Generations back you know still we have the DNA of that so from the Creator to us so it is law but it is still there that is inheritance this is what is this concept inheritances one one object inherits from another object we are going to see that in action then what is prototypal inheritance So Pro inheritance you got inheritance inheritance is able to be a us utilize the properties means the data and functions of other objects is inheritance but what is prototypal inheritance I will tell you generally inheritance is in most of the languages like C C++ Java C you will see there is a classical inheritance classical inheritance is completely different which is class-based inheritance but in JavaScript there is we don't have classical inheritance the base of we do have classes in JavaScript which we are going to see but the the hood it is basically utilizing this concept prototypal Ines this is a unique feature in JavaScript when JavaScript was met I will show you what it is like this is the feature by which an object init feature of another object in JavaScript this feature is unique to JavaScript okay though although JavaScript do have class keyword with uh release of es 6m script 6 but under the h it is using prototypal ener so what is prototypal Anis you know I told you you know in last couple of classes is almost all objects and everything almost everything in JavaScript is is basically an object how does it you know how how it is happening you know remember this for example suppose suppose we have this okay so and we have this so everything in JavaScript you know finally inherits from object this is the top level top level object we can say but even arrays and function you know what am I talking about I will show you that direction so let's go back to our [Music] browser and even letter where is the browser this is the browser we don't want this let's remove suppose we have this array equal to this we generally we create array like this right we know we all know that you know as soon as we create an array so we have this array we get output which is giving this blank array square brackets square bracket so when we say in JavaScript array instances receive this property special property known as underscore underscore Proto underscore underscore and this points to the object which is from which it is getting created or got created so when we say enter underscore underscore Proto underscore underscore so array is created using this AR variable is created using this arror notation okay which is basically and AR is receiving this internal property we have not created this is automatically received by it and by JavaScript and this is basically an array what does it what it is create that this is this we have used find index find we used it right this is basically Ally nothing but V this thing can you see that on the screen it is getting created from this function this is nothing but a d we call it Constructor function okay this is the Constructor from array Capital array this got created okay so underscore uncore Proto underscore underscore the property on this ARR object variable dot when we said doore uncore Proto is going to point to the prototype in this one so when we say when we say for example con ARR equal to like this ARR doore doore uncore Pro toore uncore this is pointing this is a special property that points to the Prototype of array Constructor function okay this is pointing to the this one when we say this this is irr dot underscore uncore Proto underscore uncore coresponding to the from where it is got created so under the H what is going on is the array when we say square bracket notation at Javas script notes what we want we want to create an array what does it do it has the array Constructor function it uses that to create this and what it does JavaScript is basically automatically provides a property to point it to point to the parent from where it was created where does it point where this property point the property points to this array this is a prototype of array array function array function is having that prototype so when we say underscore uncore it's pointing to array but what we are saying is we since it is going to point to this one but we are saying this is again a sort of a link you know sort of a link or chain to the top level obj so if we say again dot underscore uncore Proto underscore underscore we should get this right the pro the Prototype of this let's see if we are getting yes we are getting this object look at that which is having the object level properties like two two local string two string value of all these are available in this object okay so let's see let's see another example let's see example of a function what happens with the function example not want to let's say directly creat a function a and whatever it is doesn't matter what it inside this function we have created this function so when we say a doore uncore Proto it is automatically received it is pointing to this function which is which is the Prototype of this function Constructor I use the word function Constructor here okay this is actually a function Constructor which is a Constructor function all these are Constructor functions there are so many standard buil-in Constructor functions and this is a function Constructor which is a Constructor Constructor functions don't get confused okay with the help of this we create a function when we say when whenever we write this or we we either we have function declaration or function expression or whatever type it is internally uses this JavaScript internally uses this to create a function which is a Constructor function in this case this is a function Constructor the usage is function Constructor because it creates a fun fun when we write a function it knows JavaScript okay the user is wanting to create a function so it goes and goes to that function this one okay and then that's why this is point underscore uncore Proto is pointing to the internal function so if we go again doore Proto so it should point to the Prototype of this object Constructor function look at that this is again the same thing which we have seen here so it's like a hierarchy that is getting created it's a chain it's not a scope chain scope chain is completely different the lexical scope chain is different this is this is completely different this is here it is going to be a property lookup property lookup has different set of rules than lexical scope rules scope is a set of rules to find whether something exist or not in the memory as an you know as an object or function at the top level but when we go within the object or within the anywhere we I have to function is tell is an object so when we go within the object the scope rules are not applied here here rules of property look up applies so those are completely different don't get confused these are scope these are not scope chains these are chains of prototypes we call it chain of prototype chain in this prototypal we call it prototype chain so if a functions prototype chain underscore uncore Proto points to the function prototype of Constructor function or function Constructor and then if we do dot on that one as well we'll see that it's Proto the Proto of this is again pointing to the Prototype of this one so it gets linked through the underscore underscore Proto property okay it is like this and then suppose when we create an object so so what's going to happen when we say for example cost obj equal to this we are directly now creating an object we have done this several times right so when we do this what's going to happen we say obj dot underscore Proto underscore Proto what it's going to be it's object we have not created array we have not created function we are directly creating the object so underscore uncore protore underscore should be pointing to the same one right the Prototype of this object Constructor or object Constructor Constructor function okay look at that this after doing this and for this function is one in the same means this is the top level and the top level is object top level is object that's why whatever that's in by default unless and until you make any specific changes everything inates from top level is object but what happens when it goes to this hierarchy for example if we say underscore uncore Pho it is reached to the top level so this should also have the underscore underscore Proto property so when we say dot underscore uncore Proto on this one since we already are at the top level what it should be let's see let us see it is null so when when we when we reach from our level to another level to function in ARR level and to the topmost level of object Constructor or construct object Constructor construction function so and there is a underscore underscore Proto underscore property this property points to null which is an indication of there is nothing above it you have reached the top level it means we have reached the top level which is this object get it so why I'm telling you this I will show now let's create do for example suppose uh let's create a programmer function we all wants to become a programmer for one day Suppose there is uh name property here but since we don't know which programmer it is so we'll leave it as blank and programmer must know you know language we a programming language but a programmer can know multiple languages to make it plal and multiple means area otherwise we would have given okay so do coding function which is a function suppose and it is returning I [Music] am coding in I am say this. name coding in this do language and we know what this is right this always refers to the dynamic context from on which this method is going to get called right what is the problem here what is the problem here okay so let's just create an object here programmer is an object okay I wanted to create an object I don't know why I created a function anyway such things happen so let's create a object programmer which is having name property programming languages a programmer can know n number of languages so created in blank area but this program is unknown this is the say you know right now we don't know who the programmer is so that's why we can not say what the name is to do coding I am this you know and then there is an introduced function inod this function okay and return return I am I am whatever the name comes okay it's going to init like set like this for example so Suppose there is a specific programmer theal programmer that comes into this is not a real programmer just representation of what a programmer could be programmer should be having some name it should be knowing certain languages and it should be able to code and introduce itself so Suppose there is a programmer come programmer sub programmer whatever and it is an object which is having a name for example subo and it is it can also introduce itself right now it is a simple object which can inod itself and it is introducing from the the perspective of who I am simple sub obj right now I will call it as sub obj so sub obj my name is plus whatever this dot name okay got it so it is having one data property and a function so suppose we want to have cap sub obj wants to have capability of of say to be able to code so generally what we can do either we copy this or we have know we have done certain functionality over here right what we can say we can say which feature can be used we have learned that in last session if we want to you know reutilize certain functionality on another object what we can do arita goami everyone which functionality we can use just to for example sub wants to borrow this do coding then how how we can do that come on guys you not answering so in the interest of time I will show you we know that we can do it like this sub order okay for example uh what we can do we can know that programmer object is having that capability of do coding what we can do we can say bind we have learned that no we use we said that we only want to you know have this functionality of this object to be available for this object we can do bind we can do call apply bind but we want to return return a function so that user can use it later so what we can say we can say subj okay this we can do but we are not learning it is going to work right it's going to work for example we copy paste as support fod just call it look at that it worked it worked this function worked this function is not available this function is not available here cing in in this sub still we are able to utilize it with the help of with the grace of this bind function which is uh do coding function is of programmer object foring function is of programmer object by default this is dynamic it should be pointing to programmer but with the help of bind we manipulated it by passing another object so this object is passed over here in the coding object so this is Chang this is basically representing sub obj that's why when I call sub coder B is going to return return that function when I call sub coder dot this coding to coding is not available here right which is basically a same function got written B return as the function doesn't called it right way so I am able to utilize this facility right come on guys that's what I explained in the last session okay but we don't want this I want to go beyond this I want to go beyond this this is not what we want suppose suppose for example if if this function is taking okay in which language you are coding let me know and suppose it takes a parameter and and if all programming languages dot index of language exist is greater than minus one index of zero it could be either zero zero index zero to any positive Index right minus one minus one mean the item doesn't exist if greater than minus one then it exists then only do this otherwise say you cannot code return you cannot not code simple okay so when we do this suppose this is what this then this will fail then this will fail even if we are able to pass language but by by this will fail can anybody tell me because it now this coding is let me just show you first it is it is not going to work so good coder now is going to get involed first of all even if we provide the language for example JavaScript and notate properties of undefined reading index look at that we have received this error why because this programming language is not available here it did invoke this function it did invoke that's why it is giving me error it is alely telling me index of where we have used index of index of we used here on which object this. programming languages why this this is the dynamic one subj is parted in this sub coder is basically a return function this is the function which got written after bind invocation with sub obj subj becomes the context so this programming languages is not available on sub so that's what the problem is so this is not going to work so I'm going to just comment this we don't need that it can't work suppose now we we are dependent on programming languages as well suppose it is a big object and we need 10 more properties what we are going to do we are going to create copy again and again then there is no point having a design properly right so what we can do we cannot use it here what we can say now for example instead of this we should be able to do this something like so BJ doore Proto uncore uncore equal to programmer so what I am doing now I am associating creating a link sub obj and programmer obj programmer and sub obj I'm now creating assigning this the property underscore Proto to programmer let's see what happens and then and then what is going to happen we'll see that we'll see that let's see let's copy this B is not going to work bind is not going to work when uh need of properties increases so that this is the way we should let's see this in action so so OB we can directly say do coding but it takes a parameter you cannot code it takes a parameter which parameter the language parameter you why why it is telling me still you cannot quote can anybody tell me why it is telling me it is able to call the function now there is no function coding here there is no binding here we are we are saying underscore uncore prot to programmer but it is it is calling it that's why it is returning you cannot code why it is sing even if we are sending the JavaScript can anybody tell me why it is still giving me you cannot code me it is going into the else block not into the if block with and it is also not giving me error can anybody tell me why it is working but not as expected it is giving me you cannot it's not going into this one I am passing JavaScript but this condition is failing can anybody tell me why that I will tell you later just moment for introduce can anybody tell me why this doesn't go over here because programming languages is having a blank are it is not having JavaScript when we pass JavaScript to this function from here when we passed it JavaScript came here and it is checking does programming languages have JavaScript index is greater than minus one no it doesn't exist so we need to populate that what we need to tell after this we can say support. obj sub obj dot now programming languages is available over here dot push it's scar what we are going to push we are going to push JavaScript now it is going to work right and what we can say subj do do coding if I say coding blank it's not going to let me but when I say JavaScript exactly so it's going to say I'm support coding in undefined why it is telling me undefined why it is telling me undefined because I'm index of this I can directly use language over here or what language is passed or I can say just index of language I'm just you know taking that into a variable index of language and so that I can say programming language of index of language switching the index again this I can if I want to use this I could have said directly language here which is also fine it will work because it is going to take it from the parameter but just want to use this that's so when I say subj dot do coding in which language can I say C no you cannot code right now because programming language is not aware of suppose obj do coding JavaScript I'm coding in zero why I don't want this index man I want index so yeah programming language which is an item okay so I am sub coding in JavaScript so this is what is happening this subub is not having do coding it is having name and introduce so this becomes but we want to inherit you know more things then binding is not the good idea but that's why underscore uncore Proto this is how we can link one object to another object and this is how it works so what is going on here let's see so when we say underscore uncore Proto when we say so obj programming languages or when wej do coding uh in whatever language what is happening under the hood JavaScript engine when he sees this uh you know this uh as you are saying that dot programming languages it goes and check into the subj IT checks okay it's not available but it is aware that you have the underscore uncore Proto assigned to programmer so it knows it can go through underscore uncore Proto to another object which is known as programmer so it goes and check does it have programming languages yes it does have so what it is it's of type array so it understand it's an array so it's allowing us to use this method on that and just push it so programming language is going to have JavaScript and it again comes over here line number 30 it's we are saying do coding it checks into first checks into the sub obj it is not able to find superj here so it uses this underscore uncore Proto to check if you have any object attached yet yes it is so it goes and check up in the hierarchy to check whether do coding exist yes do coding exist call that method call that method with this parameter this is how it is able to call and suppose if we call supp obj do introduce method so introduce is already available over here okay so this method is going to get called right not this one this let let me just show you my name is sub my name is sub this is called this method is called can you check can you see that guys not this one I am sub a software this is not coming but this is coming it means this is known as this is known as shadowing you have shadowed the functionality of upper that's how we come to know programmer goes up in thearchy generally when we are doing Pro it doesn't tell you whether something is sub is up or programmer is up it doesn't tell you with the help of this we you can see that in action that introdu has overridden something which means programmer is came first and then sub came first introduce is there in programmer as well as in subj which means subj is Created from Pro programmer that's why introduce method shadowed the introduce method of this function this object so we cannot call this one but we can have special functionality means this is what is inheritance if you want to have your own versions you can do that but this is not we do in programming but let me show you one more thing here before we move on to the next topic uh let's say not for for in for for example let's say con property in subj let us just console do log here just to show you what comes into Sub sub look at that this Loop has printed these four properties so both obj is having only two things name data property and introduce function this one but look at that this is also is available it is telling me that programming language is also available do coding is also available but it looks like it is you know available in the subj but it is not available in subj it is basically this one this one how we will see that how we'll know that okay that this is not we say prop dot has own property this method is available has own property prop then only console.log as only if property if this sorry subj has own property if this object has own property do prop then only console.log look at that name and introduce else for example if I say obj small otherwise just console.log normal look at that so we have two properties name and introduce in subj and two properties not of subj what which means it is pointing to the upper object why it is upper we came to know it is it is it was able to Shad it means it is going up in thearchy underscore uncore Proto of subot obj is pointing to to programmer and this property are coming from them that's why it did not print this in if condition it did not go it go it went into the else condition and print those properties as program language and do coding but these all properties are available it goes up in there Arch automatically look iteration from iteration it comes to know okay this properties you know whatever is in the underscore Proto if it is pointing to anything else it it will go back and check till till whatever the user defined object we are defined this is a user defined object this is a user defined object the the for example when we say so and obj doore Proto uncore look at that this is pointing to programmer can you see theore proo it has gone into that and checked okay introduce and coding is also in coding do coding and programming language is also available in the Proto all all these four all these four are already available over here this is the Proto means this is pointing to programmer look at that can you see and when we say again doore Proto what is going to be can anybody tell me what is going to be underscore means Proto is programmer then what is the Proto uncore uncore Proto uncore uncore of programmer can anybody tell me just think if you can it is going to point to the okay let me just say it's going to point to the topmost object look at that where this has own property and all these things are available you know two string has own property that's what we use has own property is not in the subot obj we cannot see this and neither when you know when this function is going to get called what is going to happen it's going to check so is having has own property no it is not having so it uses the underscore uncore protol link because it is having programmer so it checks in the programmer does it have his own property no it's going to check the underscore uncore Proto property of the programmer when and checks does it have own property yes it has open property this is the topmost object that's why it worked if it is if if I make a spelling mistake here then it would be you know yelling at me you know there is no such property or there is no such function pushpa you get you got it why we use introduce here just to tell you that this is going to Shadow it this is going to these are separate object this is a separate object there is nothing copied here there is nothing copied here that's what I wanted to show you that and even this example proves and this also proves that introduces overshadowed it you cannot call introduce of that one here is going to call whatever is locally available it's going to get satisfied and the lookup will not after that okay did you guys get it from where this has own properties coming it's going to JavaScript engine is going to check the underscore uncore Proto when when it is not found here if it is found here it is not going to check but if it is not found here it's going to check underscore uncore Proto underscore underscore and it will reach over here because this is the Prototype of sub so it's check okay does it have as own property no so it's going to check underscore uncore Proto underscore uncore it's like going through you know when we on the ground floor we from go from ground floor to first floor using stairs we go from first floor to second floor using stairs so this uncore Proto is acting like that stairs for us to go to the another uh top level herar our top level object up in thearchy to check does it exist over here if it is exist it is going to if it is not ex going to go up till the end the top level I told you what is at the top level The Constructor function of object is at the top level this is object this one that's why it found it over here and it is working if it was not able to found over here it's going to yell us and give us the error get Itami get it but we don't use it and we don't use underscore uncore Proto I will tell you why why I explained this this is internals of JavaScript if I did not explain you this you won't be able to understand prototypal inheritance at all and if you do not understand prototypal interet you won't be able to understand objectoriented programming that's why I explained it I took efforts to make you understand nobody teaches it these days know less people anyway not let's not going into that let's not go into that and uh let's let us move on to the this much is fine right people sleeping I hope not right ARA is at least not sleeping Alami push talking properly come on get up guys and na also are available good good NA okay nain you got it Puja you got it the concept of you know what is this this property pointing to it helps us go up in thearchy to check which is the Prototype of this so we we ourselves have given this but we never do this I'm telling you why jna also got it disa also got it good okay five six people are talking okay good out of how many 7 Babu Ki SATA Saba Trisha pavitra silpa jtd M this is for you guys you should if you are able to understand let me know it's going to help me understand I can move ahead Sila yeah okay maduri say Madu did not reply jtd also not talking okay that's okay but it's for you you know anyway let me just move back okay so this is what okay oh my God it's it's already 12:26 can we take a 5 minutes break guys it's good for you as well you can have water or something anybody AR pu okay let's take a five minutes break and then we'll start again we'll continue with this topic it's very very interesting this one of the very very important you can see the the pillar for JavaScript but uh let's meet after five minutes okay let me so we were talking about this right but we don't use this because this is not that no we you will never see this in any code when you will go into the JavaScript projects you will never see just I wanted you to understand how does it work under the hood under the below the table under the the top level programming what is going to happen this is going to get happen but we don't do this explicitly this is beautiful but we don't do it because when we do it there are certain you know efficiency related problems and there are other problems that come into picture so there are better ways of doing it okay so just before moving on to the next topic I want to let you know since we have know done this just let me take you to browser okay where is our browser you can see the screen righta gotam anyone shik MSB M pu okay thanks just just let's remove this just one wanted to tell you one more thing before we move on for example whenever we create a function like this function B for example you know all functions all functions in JavaScript deceive this property prototype look at that as of now this property is useless in a normal function that we create it is going to be useful we will see that in action soon but this is all functions received you know this property because uh this is the property to which the the created instances points points to so when we created this this is but when we see the underscore uncore Proto where it is going to point it is going to point to the to the it is going to point to the Prototype of this one come on guys this function we have created a function right underscore prot should point to the Prototype of this so this is this one so this and and when we say function do prototype this is same look at that this function is the same this function f is capital you can see the Prototype is this one and B is a function user defined function created by me and it is having all functions receive prototype property for this it is blank it doesn't matter but what I want to show bore uncore Proto is this one and function protype one which means that Proto underscore uncore Proto underscore uncore points to the Prototype of the the above above function which is function. prototype okay this is what it is and functions is also having underscore uncore Proto property look at that and what it will be can anybody tell me what where the Proto will PR to the Proto will point to the Prototype of object right look at that but this is not this is again some something you know you might be wondering what it is you know this is what is a Goa this is a Constructor function and this is the Constructor function it is going to point to the Constructor of unless and until we create an instance of something like this for example we have created uh underscore when we gone from the underscore uncore Proto for example doore uncore Proto dot underscore which is a Constructor functions prototype doore undor Proto it is going to point to that the protot this is the Prototype okay right now it is not filled over here when we say this one this is not this is not an instance right now this is an instance B is an instance we have created a function and this function got created with the help of this one okay and when we say a DOT on the instance instance means realization which is having a memory which is in the memory this is sort of from where it is created this is created this function got created from this prototype which is a Constructor function itself F and C capital F okay and when we say on the instance underscore uncore Proto doore uncore Proto it is going to point to the Prototype of Constructor function object okay like I told you all functions receive just remember all functions rep receive prototype property just remember that let me write this all functions means user defined functions of course and of course which are internal these functions receive prototype property okay so let's see that if we say con obj equal to this does obj having prototype property no because it's an object right right and does array has prototype property dot prototype no because it is also not a function here arrays are behav in Behavior they are like object okay this is not receiving any such thing does for example by what is it function is so when I say string string is a function right it's a capital S it's a Constructor function there are certain you know Constructor functions this is one of them object is there does object has prototype property W it is having right don't get confused between this object and this object this is a Constructor function look at that o is capital it's not small o I'm talking about cap capital O capital O is Constructor function it's a function that's why it is having this property object dot prototype look at that it is having but the instances will not have because instances will be realization realization is instance or object okay that gets memory allocated this will also get memory allocated okay so but this is all the functions internal internal function or the function that you create like this using function this is going to receive that a do prototype just remember prototype properties available on all functions now we are going to see another topic we are good here till till now everyone there is some confusion right it's not going to get clear so if if there is any until until unless you try it yourself into the browser or anywhere else you will not know the difference but conceptually everything inherits from topmost Level capital L object okay that object with the name object is a Constructor function sometimes it is difficult to you know grasp what is an object what is a function function is an object object is a function you know people you know people who do not go into the details of JavaScript they always end up you know getting confusion and they start criticizing the language but it is not when you understand it properly many developers you know who code in JavaScript doesn't know how JavaScript Works many developers doesn't know you know many when I say many I mean more than 50% okay there are people who understand the things properly they give their time and energy and they they go to uh the level of proper understanding of the language it's a beautiful language I like this language because the way the flexibility it provides and how quickly the are two ways of learning JavaScript you can quickly learn the quickly the quickest language you will learn is Javascript when you don't want to know it and when you want to know it it will take some time there are two types of people who who work on JavaScript either there are very some people who know it there are people who know it properly and there are people who just know it at the top level so we are going into the details that's why because we want to be a good developer we don't want to be just okay you know average sort of mediocre developer right right that's not we do if you give your time make sure it is the best you are expecting out of it don't give time to nonsense things to give time to where you basically are satisfied when you give your time to so this is what it is irrespective of language no language is better than other language it all this depends on the project and the requirement so that's how you choose the tools these are different tools Java Script one of the tool C sh one of the tool Java one of the tool C++ one of the tool C is one of the tool so don't don't get into the my language or your language problem it doesn't matter these are different tools we must know how to use them okay you get it this much can we move on to the new topic just a [Music] second yeah says yes goami we are good yeah okay so let's move on to the new topic let's see no not here object oriented program just [Music] so we have this and we want to have this one just in case we want to directly use that we have this HTML otherwise there is use object oriented programming what is it sorry so you know from past 60 years 60 to 70 years I would say there is continuous evolution of the programming languages in the early 40s you know there was a machine which was very very big early 40s there was a big machine which was there known as touring machine that was supposed to be the first computer and and after that at that point in time the language mostly the you know cards used Punch Cards were used and you know some programming directly into the zero and ones people used to code in directly the machine code and then there was an advent and invention of assembling language people started coding you know slightly in know lowest level but slightly above the machine code assembly code start like and there was a evolution of language that is happening because people wanted to you know able to write in a slightly higher level where they can understand things better and they want the power and flexibility but they want to know what it is it's in a much better better as you go down towards the system Things become much much difficult to understand so there were many languages that came into which list Cam and all those in early 60s and even in early 50s there was uh a group of programmers which wanted to follow certain rules for programming for example like any program that you write the software should be basically readable okay and it should be understand able understandable and should be Memory efficient not taking too much of memory which is not called for and it should be extensible means suppose to today you write 10 lines of quote tomorrow 10 people came on to it and it should be able to enhance the functionality it should not be difficult so it should be extensible as the project grows and functionality grows it should be maintainable as the time passes maintainable means as the program goes project goes into size you know it becomes from 10 KB to say 10 MB and know this goes multiple features are coming into it should we should be able to maintain the maintain all all the changes to the code and what else of course dry which is basically do not repeat yourself which means once you write a piece of code make sure it is much more usable uh or reusable we can say that's what it is and you know as we grow there were many programming language came and it is still in use Assembly Language and then there were lisp came and then scheme came Small Talk g c C++ all this and you know it started from procedural programming to say much better Paradigm they were searching for a much better Paradigm where all these things can be done so they are going from procedural to to procedural to say uh better Paradigm Paradigm here means style of programming there are two types of popular Styles two types of paradigms are there very popular one is functional programming another one is objectoriented program these are very popular and adopted by many languages you know like c c c is the procedural of course but C++ Java C all these languages that you hear you know has the capability of objectoriented programming in c and Java only support objectoriented programming but JavaScript one of those languages which supports both type of programming and but we are going to look here this one only we are not going to focus on this one so what is objectoriented programming in objectoriented in objectoriented programming the see in since first day I I've been telling you guys for any programming language or any program that you create create in any language has two things majorly first thing is data second thing is functions which works on this data manipulates the data to achieve desired task so objectoriented programming is a way of seeing a real world problem in terms of objects and these objects are necessarily not not necessarily uh mean before realization it should be for forming a unit a unit that holds its own data and behavior together is is the unit of is the unit of objectoriented programming which can be used for uh to attain objects and objects will interact with each other passing the messages to each other whenever needed so this is known as object oriented Pro seeing the real world in terms of small units where data and behavior data variables fields and and functions put together forming that specific unit is known as object oriented programming this is our functional programming we see everything separate there is no relation between data and functions only function available pass me the data give you give you the result pass me the data give you the result that's it the function program is completely separate object Orient says that data and functions should be put together you know representing the real world problem okay so let's see that we'll see and we'll we'll go from say from we'll go from current procedural uh you know facilities and what are the problems it faces slowly we will move towards the object okay we don't have much time today but we'll see how much we can do not prototypes on object oriented let's go so we'll see first thing is function Constructor we have seen this this is one of the Constructor function the terminology is like that you know Constructor function a function a Constructor function with the name function with f Capital helps us to create a uh function is function Constructor okay gami jtd many jtds are there it's good to use name guys okay arita says yes so don't get confused slowly as you move I know I will take you step by step from one place to another place so okay there are many Constructor functions but there are the uh the function The Constructor function with the name function with f f Capital which helps us to create a function is function Constructor okay I will not tell the definition now just see this in action for example we'll take the same example of programmer we want to create a programmer for example and say suppose and we use function Constructor like this suppose I want to have two parameters name parameter and language maybe and then this is going to be the definition of the uh let's not get into details of it this is not important just want to show you move from this to uh to the Okay so programmer from here we can create subo programmer for example we say programmer [Music] or go and languages provided languages Javas for example okay let's take it to browser where where is my browser man okay SM programmer okay what is it should not be like that right should directly yes we written properly any issues with this programmer or this programmer a function should be able to call it okay not returning anything return whatever yes V just go over here and paste it super programmer and I call it with this sorry so programmer is again in object so basically this is the way one of the ways the function can be constructed but this is not recommended because of memory memory issues and many many other efficiency level things you know are not able to be happening into the JavaScript code when such programming is need so this is not at all efficient so we don't use that we don't use this use function Constructor because of its inefficiency what what is the next way we use we use uh Creator function object Creator object Creator function so let's see Constructor function there is a difference when we use the word this earlier you know I will tell you what is Constructor function for example say we have this programmer don't get confused Constructor function Constructor is this F Capital One and and any function can be a Constructor function there's the user defined function don't get confused it is confusing actually Constructor function how we do that for example we have this programmer and it is taking say name and language parameter and it's going to to return me Name colon name and language language colon language it is constructing it and do coding for example is a function again which is going to say uh I [Music] am I am this dot [Music] name software for example I am coding let me this coding in JavaScript whatever going to come up like this this language okay this do language cing in javascript. language okay so how do we use that this is we will use this function as to create to create our objects okay so how do we do that con let me just call it one so as programmers for example I I want to create sub programmer equal to programmer 1 dot name of subo for example language JavaScript it's already there that's why I can say one so this is the one way of creating another way of creating so subot programmer should have all the things right and when I say do coding see we created one another object I am sub coding in JavaScript so when I say sub programmer one do do coding I created new object I can create another object for example say har programmer one equal to programma one h maybe he's coding in uh C++ I don't know so har programmer not do coding so we should be it should be working let's see I already coding in C++ see we are able to create objects with the help of this function we are not you know again and again creating the data but what is happening here is you know there is one issue here you know what is the issue this programmer function is definitely a Constructor function it is basically constructing for this object and this object so see data repeating is fine because data is going to be different from this this object to this object but this functionality is also getting copied means do coding of this is again is getting har programmer is having his own do coding and sub programmer is having his own do coding we don't want this right we our this is is not much efficient so what we can do in this case we can to solve the problem to solve the problem of code duplication or logic duplication code or logic duplication because we want to follow the principle of these principles right we want to follow this principle readable understandable memory efficient extensible maintainable do not repeat yourself you want follow this that's why we are giving proper names you know like this but we one two and three we generally don't give but since we don't we are doing for illustration and understanding the conceptual part of it we are okay with that to solve the problem of code logic duplication which we can do we can just take this function out of it and we can say uh just just copy this one again and put it on over here we can say programmer one and set to just to save the time and we'll remove this code from here and create a new object F programmer to functionalities obj common functionalities we common functional it is object whatever okay and this is an object we can just put it over here and you can say return or just or just do it like this don't want to return this is an object so do coding instead of this what we can do we created this object what we can do one thing is we can do do it like this do coding equal to Common functionalities OBG do do coding okay then this is going to work it should be actually printing you know that thing properly let's see if it works what we are doing essentially here we are not we are we have just removed it from here to this one and we have this common object having this function fun ality to coding for us okay and this programmer to is not having that and we have just assigned this to this property of har programar and so we can do this right you know it property can be assigned like this so we can do like this okay spelling mistake let's go to browser and pasted I am undefined coding and undefined why this is happening can anybody tell me I am undefined coding and undefined anybody Dita puita Ki this is it is not getting the this thing that's why yeah okay the problem is in the code I made this mistake that's why I should be calling giving the preferences not calling it right let's see and I want to say subot programmer to do do coding see so both programmer 2 do it is coming properly and for Harry programmer 2 dot do coding it is coming properly now because I made a mistake because I want to give the reference of this today I want the definition to be available over here the common definition right I made a mistake sha jtd thear VI chandu madri Ki you getting Itami nain I made a mistake I called it like this I should not be doing that right I don't want to call it I want to give the definition to be to the this property that do coding property of this Pro you know the object we have created I created the new property to coding and wanted to give the common functionality to it that we can do right I don't want to call it right here I want user to call it whenever he wants user of this code right that's what the mistake was this is what we do it but again you know uh know this is how we are able to take out the common functionality but this also is having a problem you know what problem is suppose there are 10 common functionalities or common functions then I will have to give 10 Common functionalities to here again and again doing 1 2 3 4 5 6 7 8 9 10 and to Har programmer also so I can I have to give all those 10 functionalities now imagine such 500 objects are there I am not going to do that 500 objects 10 functionalities per object I have to write that I will tell no to my senior and say no this is not a design I want right I want a better design so let's move on how we do that we can use there is a problem you got it right there is a the problem here is the problem is the code is not extensible the code is not extensible properly if as we increase the number of common functionalities the code to use that also increases and if for one object imagine there are 500 such objects are required there so unnecessary those those will get 500 different level of coding right into the memory it will take memory and everything it's going to be very difficult so how we solve this H how we solve this that's where another functionality comes into picture is using object do create this is pure prototypal inheritance and I am showing you real prototyp Ence in objectoriented program okay so what we do we just copy this no not this one we'll copy this one and just put it over here and just we'll say let it be let let the common functionalities be whatever it is let me just it okay we have this common functionality now instead of doing this thing what we are going to do we are going to say const new obj equal to new programmer equal to object do create you know object do creates a copy you object to use as a prototype maybe null creates an object that has specified prototype or that has null prototype so whatever the object we provide it will create a new prototype of it so like this common functionalities we can provide it over here and here in this we can say dot uh name equal to name and new programmer dot language equal to language and we can return this return new programmer we can create this is pure prototypal programming we are creating prototype based on object. create of this functionality and we are just assigning set properties to it so what we can do here we can just [Music] see and we are going just renaming this thing the code doesn't conf each other and we are returning so instead of programmer two we have to say programmer 3 just because it is in the same file I'm doing it right it is not required otherwise is a functionality so what it is doing it is calling this one and pro sending the name in language and object. create is the way in JavaScript where you can do real prototypal inheritance and where it is going to inherit this create a new object and returns that and with the help of the the parameters which are received in name language we can create new properties name and language whatever and then uh return that and we don't need this now can directly call that right it should work unless and until I have made a mistake of spelling at least common function object is not dependency I made a mistake so don't be worried look at that this is printed har coding in C++ but why this is not printed is there an issue with this programmer 3 do do coding I am coding in JavaScript is also so it's working fine right the do coding is able to get the proper this one so we are making use of the dynamic nature of this so this is very useful very useful when you want to preserve the dynamic nature of it you know and this is what is working the way it is it is it is when we when it is calling programmer 3.2 coding it is able to get the proper object whatever we have passed like this okay but again this is even this is the real prototypal people don't like it I don't know but many many of the JavaScript Community doesn't like it they want much better X way of using it so there is another way of doing it we are slowly slowly moving towards the object orientation that's why I'm showing you all the ways of creating the object arita oh my God it's 110 do you want to continue or we can do it on Monday not an issue I think this is okay we can do it on Monday Monday is quickly saying Monday okay I get it guys I get I understand everybody's saying Monday okay Sabah nishar okay no no issues no issues actually I did not look at the clock that's why 10 minutes Cav yeah okay so goami gotami I think she got she slept I think she's sleeping aami can we do it on Monday Ash says Monday okay probably okay anyway so let's you know no I was just joking I know okay so let's stop it here you know we'll continue directly from here itself into the day 24 you know and we show you one more way is remaining I will show you that way and we'll move on to the object orientation okay that we are going step by step I could have directly used Class keyword is available but you would have got nothing you know from out of this how we raed it I'm telling you each and every with example and what are the problems are there you know that's why okay guys I think we should be doing this much today