Hey ninjas, I think it’s about time we started using constructor functions to create our objects! So in this JavaScript tutorial for beginners I’ll introduce it to you!
The constructor function is useful if you are creating many objects of the same ‘type’ – e.g. many different Car objects. It promotes DRY code (don’t repeat yourself) and saves a lot of time when creating many objects!
Any questions, fire away 🙂
SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1
========== JavaScript for Beginners Playlist ==========
========== CSS for Beginners Playlist ==========
========== HTML for Beginners Playlist ==========
========== The Net Ninja ============
For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk
========== Social Links ==========
Twitter – @TheNetNinja – https://twitter.com/thenetninjauk
Original source
13 responses to “JavaScript Tutorial For Beginners #30 – Constructor Functions”
Isn't this a Factory Design Pattern?
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?
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…
var a = {
fun: function()
{
document.write("hell");
}
What is the difference between a.fun() and document.write(a.fun())?
Finally I understand constructor functions purpose! Thank you!
THanks ninja 🙂
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!
You can actually start the constructor function without adding 'var':
function Car(speed, driver) {
thank you shaun, you're my real ninja!!! 😀
Nice tutorial man!
What's the difference between a constructor and a regular function? Why and when would you use one over the other?
This explained it better than my teacher did at school. Thank-you!
Where the semicolon is necessary to end a statement in javascript?
excellent tutorials tyvm!!