JavaScript Constructor Functions made simple.
🔥Get the COMPLETE course (83% OFF – LIMITED TIME ONLY): http://bit.ly/2M1sp4B
Subscribe for more videos:
https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1
Want to learn more from me? Check out my blog and courses:
http://programmingwithmosh.com
https://www.facebook.com/programmingwithmosh/
Tweets by moshhamedani
Original source
16 responses to “JavaScript Constructor Functions”
God gifted mind to Mosh
Bro…you rock! Great tutorials man, thumbs up on all of them. Of course I subscribed :-))
You are genious, explaning each piece of code in clear manner!
Thank you!!
Wow javascript programmers are retarded when it comes to indentation.
Running the code and showing output in the console would be helpful
The only thing I don't understand is setting this.radius = radius. What is the purpose? It's saying object.parameter = parameter
I prefer factory functions
Constructor function looks unnecessarily complicated. Factory function is quite simple.
Mosh … Why you are not in Udemy …
Nice js talk! I’m learning something new everyday… thanks
The new keyword also sets the prototype of the object to its parent which is Circle
e.g Object.setPrototypeOf(newlyCreatedObject, ConstructorFunction)
Ok well. Which one is faster? I think Factory Functions are faster and Constructor Functions are spending more performance.
And what about ES6's classes? What's the difference between this way of creating objects and classes?
Mosh explanation is always very neat and good.
My 2 cents about this topic:
Factory functions are a more reliable way to make objects.
Objects created via constructor have binding problem, those objects simply lose their scope in some occasion.
JavaScript is a functional programming language natively, not an object oriented one.
Messing with prototypes can have a bad impact in terms of performance.
Why not include the new ES6 notation with class and constructor?
The code would read something like:
class Circle {
constructor(radius){
this.radius = radius;
}
draw() {
console.log('draw')
}
}
const myCircle = new Circle(radius)