Is this understanding of object constructors in javascript correct?
function Bird() {
this.name = "Albert";
this.color = "blue";
this.numLegs = 2;
// "this" inside the constructor always refers to the object being created
}
let blueBird = new Bird();
- Bird() is a function, that is also at the same time, a object constructor.
- After
let blueBird = new Bird()
then the real object has been created, which isblueBird
- So right now, object blueBird is:
let blueBird = {
name: "Albert",
color: "blue",
numLegs:"2"
}
edit:
4. then the newly created object blueBird is an instance of object constructor Bird() correct?
can one object constructor has multiple instances? they can right? every time you pass in arguments into object constructors then more and more instances (newly created objects) are gonna come out right?