Access Modifiers & Modules - TypeScript [Protractor Tutorial] | LetCode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] they'll go back to late code my name is Kaushik in our previous video we have learnt about classes and constructed with thirds and variables using type scape today we are going to learn about access modifiers and modules before getting into the access modifier and modules let us first install the type scape so far we have used typescript online compiler or the Keuka plug-in that no need of installing types kit that can easily do the stuff for us without installing typescript also that is going to work for sure but now we are going to use the type shape in our wheels for the installation is very simple just we have to use the NPM to install the types cube so I'm just going to copy this and if I go to my PS code and ctrl J to bring up my terminal and then simply you have to paste it there right so npn so node package manager and if you are using the install command to do the installation and - C stands for global and then followed by the package name that is our type script so let me close this and here we know that this is our class called Mobin and we have this private variable and public variable right so apart from this we also have a B or not variable we also have access motif is known as read-only so let's consider that we have a mobile that has IME number right now ima number must not be changed right so it cannot be also duplicate so that's not let's not worry about that let us see how to make this ima number not changeable by anyone so here I am going to say it will only and then 4 by IMEI and I'm going to just give some value to it and we also know that this is going to be of alphanumeric so of course I can use this here that's fine right now here using this main mobile object if I try to access those so console dot log then four by the object name then followed by the variable that is IME right now if I go to my terminal and of course I have to move to this folder first so CD then followed by previous books and here we have to compile the files right so we cannot run the file directly of course there is a way we will talk about that maybe in the next video as often let us understand the traditional way of type script how it works actually so here we have to compile the file so you we have to use the command called tac here is nothing but typescript compiler and then followed by del finally so here I am going to say tac then front by the file name that is mobile RTS now this compiler is going to convert not convert actually transpile the code into JavaScript file so here within this T is oops folder see we can see we got a file called Ohio J's now if you go it's in this here you can see it has converted all the code whatever we have written there in terms of JavaScript and here we are also getting some mirror so let's not worry about this because these are coming from selenium webdriver package not from our package so nothing worry about it so let me just clear right up and here I have to run my JavaScript file I cannot run my type script file so here I have to say before that let us see here we are getting some exception right so it says that duplicate identifier phone because both the classes have the same name so that's not a problem that's me as code is giving us something but that's not actually a problem so here if I go and close this mobile dot J's files now and if I say here it's going to work for sure so that's not a problem that's actually given by the B's code so let us try to run this now so know then for by mobile dot J's please remember you have to run your J's file not the TS face so if I hit enter here you can see hey call it that is coming from this method and then followed by this IME number using this value using this variable right that's absolutely fine now let us try to change this value so here I am going to say my mobile dot I am I equal to some value right so I am just going to give some value here now as soon as I do your compiler says that hey Koscheck you are trying to access a read-only value that is not possible you cannot change the value of a read-only property we understood that read-only means of course we cannot change the value but we can access it anywhere so what is the difference between public private and read on so public basically means we can use this variable across anywhere so it can be inside the class outside the class or outside of the package or folder so we can use it anywhere within a a project that's it right whereas private means we can use that within our class itself we cannot use that outside of the class so that is how private works and read-only means it is similar to your public but with read-only access so you cannot write it or tree modifying it in anything so that is the read-only now that brings up senator questions like what is the difference between cost and read-only because we know that constant is also similar to read-only where if you declare something we cannot change that in anywhere so that is also that is the use of constant that's absolutely fine but the major difference is we use read-only for the member function of a class that means any variable declared within the class we can use read-only for example here I cannot change like this so let me just copy it here and here I can say constant so that is not possible we know that within the class we cannot declare cost let or power that we only talked in our JavaScript video so probably you have to check that out so here we know that we cannot use this constant area between the class and the class variables but whereas I can use this Const or anything within my functions or the method so here I can paste and this is going to work for sure now here if I try to change this so that is also not going to work for sure so here I am did saying something like that now here also we are getting something some error says that he Koscheck you're trying to assign a value to the constant that is not possible so this is the difference so if you want to change so if you don't want to change your variable that are present in the class level class variable then you have to go with this read-only where as constant is also similar to read only but it can be accessed or declared within the functions or the class methods so that is the difference between read-only and constant so we understood what is private public and eight only now let us understand what is the concept of module so model is basically introduced in the JavaScript 2015 motion so mostly whatever we are going to write like functions or the classes or any method within the functions of the variable or anything we cannot use that outside of your model we know that writes in now JavaScript video also we saw that to use the class outside outside outside of the sensor to use the object or to create the object in anywhere we have to export our class aside so then we have a syntax like let me show you that so if I go to this oops concept and if I go to this class assign method and here we can see that we have export our classes right so here we did the export first so where was that yeah so here we export this and then within this class we have used this using the request statement so this is how we have to do in JavaScript but in typescript it is going to be very much simple so here let me come on this so it's not possible so here we have to say this class this model I want to use this model right so here I have to say export and that's it we can use this class anywhere to import this class let me create another class here so I am going to create an the class as my mobile or TS and Here I am going to create the object for this so let us make this as constant and then we can say my mobile equal to new then followed by the mobile that is my class name right so if I do like this and here you can see it already done the input statement for us so whenever I am going to write like this control space so let me just show you again so mobile and then it is going to bring up this pop-up and also it says that auto input so when I hit enter it is going to do the import statement for us right so here this import keyword so that means we are importing something from the other classes and this is going to be your mobile that is your class name and from is the keyword like from where we are getting this noble class so here dot slash means current folder and this mobile is our actual file name okay and here we are getting some exceptions because of course we have to add the model name and the number in our constructor so here I am just going to quickly give like and maybe something like that that's it right no here and here we know that this mobile is going to be of type mobile right so I can explicitly say that so here I can just cubes colon and here I can say like this so this is also pretty much fine now if I try to call something so here I can say my mobile dot and then I am a equal to some value so again this is not possible because we know that our ia is read-only property that's fine now let us try to call some function so here I would say my mobile then for by make call and here if I go to this of course I cannot run directly so again I have to the transpile I mean I have to do that compile so here I am going to say CD then followed by my mobile now let us if you notice here in this particular folder we have this mobile and my mobile yes now as soon as I do this here you can see we are going to get a new file called my mobile dot J's right so here we can see we got this and here if you go inside this you can see we are able to see the require statement so internally everything is compiled to the JavaScript so from the JavaScript only typescript is able to record right tribe scape has the some features like read-only properties or if you keep you straight data type so that is why typescript is famous but of course javascript is select mother language so comparing two types cube so if you know JavaScript then learning typescript is very easy so don't worry about types you even just learn in the go so nothing much there are differences but you have to be strong in JavaScript so let me clear this and let me call my node then followed by my mobile dot J's and that is going to work for sure right so here we are getting this high calling and thus followed by now we are getting hey calling two times because because here also we are able to call this right so when we create object here also this thing's is calling so that is the reason we are getting place so what can I do is I can simply come and sout good and you know if I go to this particular place let me recompile it again and if I run this now so here it is going to give us a call Emma right so that's absolutely fine so in this video we have learnt about what is the use of read-only and what is the use of public private and also we understand the difference between read-only and constant so in the next video we will learn about inheritance concept in time scale so thank this thanks for watching see you in the next one if you liked the video consider giving a like and subscribe to the channel [Music]
Info
Channel: LetCode with Koushik
Views: 1,695
Rating: undefined out of 5
Keywords: letcode, letcode koushik, typescript, typescript tutorial, readonly vs const, readonly vs constant, import export typescript, access modifiers in typescript, protractor tutorial with typescript, protractor tutorial, automation testing, ts modules, ts readonly, typescript classes tutorial, typescript class constructor, typescript classes, typescript class example, vs code, install typescript, install typescript in visual studio code, ts node
Id: RhNtrkW_Bt4
Channel Id: undefined
Length: 12min 52sec (772 seconds)
Published: Sat Jun 13 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.