JavaScript Tutorial For Beginners #30 - Constructor Functions

  Рет қаралды 93,332

Net Ninja

Net Ninja

Күн бұрын

Пікірлер: 89
@dinaradukan5221
@dinaradukan5221 7 жыл бұрын
These are the best Javascript tutorials I have seen so far. Easy, concise, to the point and explained in an very logical way. Thank you! I'm a huge fan of your teaching method.
@NetNinja
@NetNinja 7 жыл бұрын
Thanks :D
@fusiondew
@fusiondew 2 жыл бұрын
I've learned a couple languages, and you've made javascript the easiest with your tutorials. you've accurately covered all programming fundamentals in 30 videos I'm impressed!
@vladirimus7731
@vladirimus7731 7 жыл бұрын
You have a real talent with teaching.
@NetNinja
@NetNinja 7 жыл бұрын
Thanks :)
@vladirimus7731
@vladirimus7731 7 жыл бұрын
Put your course on Udemy. You'll have plenty of clients.
@FireXFist
@FireXFist 5 жыл бұрын
@@NetNinja just found you in 2019. you do!
@oloruntomiojo9433
@oloruntomiojo9433 4 жыл бұрын
Found him in 2020. Thanks a lot man
@MaxJacobson1
@MaxJacobson1 8 жыл бұрын
This explained it better than my teacher did at school. Thank-you!
@caseyvandyke7051
@caseyvandyke7051 5 жыл бұрын
That's cool. I didn't even know they taught JavaScript in school.
@vincecaruso6465
@vincecaruso6465 4 жыл бұрын
I agree with Thom... done quite a few in the last several weeks, this is the clearest and most easy to understand.
@pawpaaj
@pawpaaj 8 жыл бұрын
This is really well explained, once I tried to learn constructor functions from a book and couldn't get it. I've learn it easily from this tutorial, I've found out that those functions are quite simple. I guess I don't have talent for learning from books or you're just a good teacher!
@joellim7010
@joellim7010 7 жыл бұрын
simply the best explanation about constructor function i have ever seen in my life!
@CameronChardukian
@CameronChardukian 5 жыл бұрын
Watching this video helped me finally get close to fully understanding object creation and its purpose in Javscript. Thank you!
@tonchita91
@tonchita91 7 жыл бұрын
I just noticed, after 30 videos how awesome the thumbnails are
@Mirzly
@Mirzly 6 жыл бұрын
This is the best lecture I've seen on Constructors ever.
@Alex.Shalda
@Alex.Shalda Жыл бұрын
8 years past, still great value 👍
@zacharyallenkravits2712
@zacharyallenkravits2712 5 жыл бұрын
I understood the concept of constructors in JS but, for some reason, this video helped make the 'this' keyword click for me. Been struggling with 'this' lol. Thank you
@trups11trupti
@trups11trupti 6 жыл бұрын
Excellent way of teaching difficult concepts into easy understanding way. It would be nice if you can add more concepts like call, apply, bind, arrow etc...with your excellent way of teaching. Please let me know if you have any tutorial on this or create new one.
@brian_ham
@brian_ham 5 жыл бұрын
The way u explained was very easy to understand. Thanks so much
@Bergamoism
@Bergamoism 6 жыл бұрын
Again and again. When I don't understand a concept, I come here and (light bulb!) Great job Shaun!
@robinkartik6356
@robinkartik6356 7 жыл бұрын
Like the way you teach Constructors.
@VadimRob
@VadimRob 8 жыл бұрын
Finally I understand constructor functions purpose! Thank you!
@kylemondina-6b509
@kylemondina-6b509 7 жыл бұрын
OMG THANK YOU SO MUCH FOR THIS VERY CLEAR EXPLANATION!!!!
@pastuh
@pastuh 6 жыл бұрын
Thanks, easy to understand. Now its time to create A.I.
@it_jedi_onchill
@it_jedi_onchill 6 жыл бұрын
You're the best teacher in my live! I don't like teachers in Russia. You're my teacher #1!
@vashisthegde192
@vashisthegde192 6 жыл бұрын
Hey! Net Ninja, I did not understand the part where you deleted the basic definition of the object... how did it work even though you deleted the whole object definition? Great tutorials, by the way! Keep up the great work!
@binarycodec
@binarycodec 6 жыл бұрын
straight to the point. Thanks man!
@Andrea-lf3jq
@Andrea-lf3jq 4 жыл бұрын
Thank God for this man
@andyp.6545
@andyp.6545 2 жыл бұрын
Konstrookta foonkshen is de veri bestest foonkshen in de wold!!!!
@Jono_1987
@Jono_1987 7 жыл бұрын
This and the previous video left me thinking, Why is it so difficult for other people to explain this in JavaScript!
@gianniprocida3332
@gianniprocida3332 2 жыл бұрын
Wow! Amazing content. Amazing KZbin Channel! Thank you
@manhill8833
@manhill8833 4 жыл бұрын
Love how you hit the keyboard like Lars Ulrich hits the drums. Luckily you seem to have a more patient personality.
@NetNinja
@NetNinja 4 жыл бұрын
lol. I invested in a slient keyboard for my newer videos.
@kaypakaipa8559
@kaypakaipa8559 7 жыл бұрын
wow this is beautiful teaching, thank you DR Ninja
@NetNinja
@NetNinja 7 жыл бұрын
Thanks :)
@daniel....
@daniel.... 8 жыл бұрын
You can actually start the constructor function without adding 'var': function Car(speed, driver) {
@Yohina1989
@Yohina1989 7 жыл бұрын
I was wondering if there was a difference between var Car = function() vs just doing function Car(){}
@TRIBISTHEGAWD
@TRIBISTHEGAWD 6 жыл бұрын
You should always use the var keyword to declare variables. Why? Good coding practice should be enough of a reason in itself, but declaring a variable without the var keyword means it is declared in the global scope (a variable like this is called an "implied" global).
@ibrahim47
@ibrahim47 5 жыл бұрын
it's a good practice to demonstrate that functions in JS are actually objects !
@Shit873
@Shit873 8 жыл бұрын
Nice tutorial man! What's the difference between a constructor and a regular function? Why and when would you use one over the other?
@aduonye
@aduonye 5 жыл бұрын
Sir, how where you able to use your code editor and the console at the same time? I see you write your JavaScript in your code editor and see the result in your console. How did you do that? Thanks for the videos.
@The_Nova_Glow
@The_Nova_Glow 4 жыл бұрын
well done mate.
@hamzashabbir3265
@hamzashabbir3265 2 жыл бұрын
hello sir, i have a question which is "what if a user wants to enter the values of time and maxspeed, so how we can make our site possible to do that?"
@rohansharma4971
@rohansharma4971 6 жыл бұрын
so, is constructor functions similar to a normal function ? And the only difference is the usage of new keyword for constuctor function??
@yazidbustomi9115
@yazidbustomi9115 8 жыл бұрын
thank you shaun, you're my real ninja!!! :D
@NetNinja
@NetNinja 8 жыл бұрын
Haha, thanks Yazid! :)
@Jack-CS
@Jack-CS Ай бұрын
I understood (or thought I did) the previous "This" lesson. Why do we need to use "this" here, if the instances of Car all have different names, why do we need to tell the code it's this specific one we're working on. Is it not assumed by the fact each instance of the object has a different name? Surely when it assigns the attribute, it knows it's going to e.g myCar2, so why do I then need "this" within it? Brains melting lol
@pragun1993
@pragun1993 6 жыл бұрын
Hi, this is a bit tricky. Initially what you said was that 'this' keyword refers to the object based on the context in which it is operating. So if 'this' is used inside an object like `var mycar ={ this.name='Audi'}` then 'this' refers to mycar object. But in the example provided 'Car' is defined as a function and not an object. So, what does 'this' refers to inside an function. And when you're writing `var mycar = new Car()`, technically it should return a value which you have not defined in the function. So, how do we get an 'object' returned?
@rudyNok
@rudyNok 2 жыл бұрын
I know right? Just a sidenote - functions in javascript are also objects. But the magic happens because of the keyword new. Here is what the keyword new does: 1. A new empty object is created and assigned to this. 2. The function body executes. Usually it modifies this, adds new properties to it. 3. The value of this is returned. So this in the constructor function doesn't refer to the function itself if you call said function with the keyword new. That's how I understand it.
@pragun1993
@pragun1993 2 жыл бұрын
@@rudyNokYes. Thanks for replying. It's been quite some time. But i got to know this later when I read portions of 'You Don't Know JS'.
@tasnianishat3194
@tasnianishat3194 5 жыл бұрын
Net Ninja , can you tell me about the problem with constructor i read in somewhere. It said "The major downside to constructors is that methods are created once for each instance. like logDriver() of myCar1 and myCar2 looks same. but those methods are not the same instance of Function. so when i check it with alert (myCar1.drive == myCar2.drive); it gives false. but why it happens? and how to solve this ?
@vigneshsrinivasan9692
@vigneshsrinivasan9692 5 жыл бұрын
is it right to say that var Car is a class?
@jsnode2075
@jsnode2075 7 жыл бұрын
However you are way faster than the ninja man but I have one question, suppose, if I have to call 20 cars, so iI need to write 20 lines of codes for only calling the constructor, is there any ways to go for loops, if yes, then how?
@returnedfaith7254
@returnedfaith7254 6 жыл бұрын
It's not nice not to leave a comment when you have learned so much from this video.
@NetNinja
@NetNinja 6 жыл бұрын
Thanks :)
@chandravadhanaa3924
@chandravadhanaa3924 3 жыл бұрын
Defining a function, function Car(){ //some code } is exactly the same as var Car = function(){ //some code } Am I right?
@daksh6752
@daksh6752 7 жыл бұрын
Can you please use the dark theme?
@federicocucinotta9977
@federicocucinotta9977 7 жыл бұрын
Hi, I love your videos! But I had a question about this one. Isn't a constructor function the same as a class in this case? Thanks in advance!
@kaypakaipa8559
@kaypakaipa8559 7 жыл бұрын
hi, I think A class is the encapsulation of the definition(name & template) & creation of an object, whereas the constructor seem to only be the definition of object. it is the template of an object, and the template itself isnt an object until called to be created. values are passed thru it and an instance is created. thats my understanding of it, but hey i might be wrong, still learning too,
@federicocucinotta9977
@federicocucinotta9977 7 жыл бұрын
Thank you very much for your response, if you are correct then classes would make it easier for me to organize my code!
@siddhartharao8490
@siddhartharao8490 8 жыл бұрын
var a = { fun: function() { document.write("hell"); } What is the difference between a.fun() and document.write(a.fun())?
@alexschmidt4371
@alexschmidt4371 4 жыл бұрын
So constructor functions are similar to classes in other languages like C++ or Java!?!? You declare the class/constructor and then you can make as many objects as you like in the same syntax.
@asitprakash6445
@asitprakash6445 5 жыл бұрын
the : used in constructor function was throwing me error but instead of : when i used = it was working perfect
@kiritokirigaya6065
@kiritokirigaya6065 7 жыл бұрын
I wrote the exact code and chrome keepsaying unexpected error on the this.maxspeed = maxspeed ; , i dont know why ! Why ?
@greencoder7419
@greencoder7419 6 жыл бұрын
Why do we need to do this.maxSpeed=maxSpeed inside the constructor function. Why can we no do maxSpeed=maxSpeed?
@grantseguisa
@grantseguisa 8 ай бұрын
how did the speed got changed to 30? when the max speed was supposed to be 10? im quite confused
@grantseguisa
@grantseguisa 8 ай бұрын
ohh nvm, it was from the first car my head boutta explode 🤯🤯🤯🤯
@vityachess
@vityachess 2 жыл бұрын
Is this actual on 2022?
@hrishabhbairagi2420
@hrishabhbairagi2420 8 жыл бұрын
THanks ninja :)
@admiralrohan
@admiralrohan 8 жыл бұрын
Where the semicolon is necessary to end a statement in javascript?
@MrBradleydoering
@MrBradleydoering 6 жыл бұрын
I'm getting an error when I try to save this exact code in brackets: ERROR: 'console' is not defined How can I fix this?
@AbdullahMahmoods
@AbdullahMahmoods 6 жыл бұрын
go to bracket's extension manager. there go to the installed tab and find ESlint and disable it
@MakeRandomVids
@MakeRandomVids 5 жыл бұрын
Why doesn't this work? I would assume this to work..: let Car = function(driver, maxSpeed) { driver: driver; maxSpeed: maxSpeed; // this.driver = driver; // this.maxSpeed = maxSpeed; };
@lardosian
@lardosian 6 жыл бұрын
But Shaun you are James Bond, admit it...
@razzchaudhary9184
@razzchaudhary9184 5 жыл бұрын
a constructor is just a function that create ???
@matthewmcfadden933
@matthewmcfadden933 4 жыл бұрын
It didn't work. It says Unexpected token 'var'
@jonnywilson375
@jonnywilson375 7 жыл бұрын
Isn't this a Factory Design Pattern?
@JurajPecháč
@JurajPecháč 6 жыл бұрын
JavaScript Factory Functions vs Constructor Functions vs Classes medium.com/javascript-scene/javascript-factory-functions-vs-constructor-functions-vs-classes-2f22ceddf33e
@ziadmohamed1416
@ziadmohamed1416 6 жыл бұрын
I cant get it , why did you write [ this.maxSpeed = max speed ; ] can anyone can suggest me a video to watch to understand this, please
@matteuspittmann2720
@matteuspittmann2720 6 жыл бұрын
hey man, i wasn't sure if you got this figured out or not. But basically since in a constructor function you are constructing a new object that will take parameters you set in the parenthesis. So you'll want to tie those parameters to the properties like so: var Car = function(maxSpeed, driver){ //this is the object name & the parameters it will take //the following steps bind the properties to the parameters for when you create a new instance (or a new kind of version of this object). tthis.maxSpeed = maxSpeed; this.driver = driver; this.drive = function(speed, time){ console.log(speed * time); }; this.logDriver = function(){ console.log("driver name is " + this.driver); }; }; // Since you bound Car's properties to the parameters, you can just enter in your custom values to those parameters. Thus creating a new instance looks like this: var ziadsCar = new Car(100, "Ziad");
@BKofficer23
@BKofficer23 5 жыл бұрын
Thanks Matt
@tomasmatusek6292
@tomasmatusek6292 3 жыл бұрын
@@matteuspittmann2720 yes, but bro I had same problem, I understand him, necause if u see,,driver have name yes,and same max speed had value, question is, if i can from function called back name of driver, how i can called back maxSpeed, i try that little bit hack, but .. like make for maxspeed function, but it not working var Car = function(maxSpeed, driver){ this.maxSpeed=maxSpeed; this.driver = driver; this.drive = function(speed, time) { console.log(speed * time); }; this.logDriver = function(){ console.log("driver name is " + this.driver); }; this.maxSpeed = function (maxSpeed) { console.log( maxSpeed); }; } var myCar= new Car(70, "Tomas"); var myCar2 = new Car(170, "Maja"); myCar2.maxSpeed(); myCar2.logDriver(); Im not sure that somebady will answer me, if i see its 3year vidio yes, but even that,maybe somoene had same problem.
@tomasmatusek6292
@tomasmatusek6292 3 жыл бұрын
problem solver: var Car = function(maxSpeed, driver){ this.maxSpeed=maxSpeed; this.driver = driver; this.drive = function(speed, time) { console.log(speed * time); }; this.logDriver = function(){ console.log("driver name is " + this.driver); }; this.maxSpeed2 = function () { console.log( "maximalni rychlost je "+ this.maxSpeed); }; } var myCar= new Car(70, "Tomas"); var myCar2 = new Car(170, "Maja"); myCar2.maxSpeed2(); myCar2.logDriver();
@kiritokirigaya6065
@kiritokirigaya6065 7 жыл бұрын
Im a bit confused
@aidengrant3633
@aidengrant3633 6 ай бұрын
Doesn't make sense to me, syntactically I mean. Car should be a function, and this must be referring to the parent object that the function resides in. This is one of the most bonkers syntax I've seen in JS, it's just too arbitrary and against convention.
@realcconnect6873
@realcconnect6873 4 жыл бұрын
nothing I understand, uhhhh, very bad, even there is no source code
@sayedhasancp
@sayedhasancp 6 жыл бұрын
bad tutorial.................... not well explained...... just made with the little bit of basic..............
@shoummorauth
@shoummorauth 7 жыл бұрын
Bro I am facing a problem. The problem is the starting sound of your videos is so annoying! and I don't want to skip any part of the video because it's distracting. Also, if any old guy want to start learning from your video then I don't know what's gonna happen...
JavaScript Tutorial For Beginners #31 - The Date Object
9:23
Net Ninja
Рет қаралды 85 М.
What is Constructor Function in JavaScript? - JS Tutorial
17:40
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,9 МЛН
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 27 МЛН
Functions vs Classes: When to Use Which and Why?
10:49
ArjanCodes
Рет қаралды 165 М.
JavaScript the Basics - Object Constructor Function
6:27
Rob Merrill
Рет қаралды 47 М.
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 121 М.
The Importance of THIS in Javascript
22:59
developedbyed
Рет қаралды 22 М.
Higher Order Functions - JavaScript Tutorial
10:10
ColorCode
Рет қаралды 69 М.
Object Oriented JavaScript Tutorial #10 - Prototype
8:24
Net Ninja
Рет қаралды 199 М.
Visually Understanding JavaScript Prototypes
14:58
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 55 М.
Callbacks in JavaScript Explained!
14:03
Code with Ania Kubów
Рет қаралды 154 М.
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 4,9 МЛН