I am trying to understand why the function Fruit works when making an object:
function Fruit(name, color, shape){
this.name = name;
this.color = color;
this.shape = shape;
}
var apples = new Fruit('apple', 'red', 'round');
Why is it not the following:
function Fruit(name, color, shape){
name = this.name;
color = this.color;
shape = this.shape;
}
if, for example, the name after the equals sign is what is pointing to 'apple' and this points to the parameters in the var apples wouldn't it make more sense to put this after?
Sorry in advance if I didn't phrase the question properly.
To clarify why I don't understand it let's change the names so that they aren't the same:
function Fruit(name, color, shape){
this.thename = name;
this.thecolor = color;
this.theshape = shape;
}
var apples = new Fruit('apple', 'red', 'round');
And that would still work because the object apples would be {thename: 'apple', thecolor: 'red', theshape: 'round'}
so then isn't it thename = 'apple' if you had thename = this.name in the function?
=), which assigns the value of its right operand to its left operand"