I learned javascript inheritance via the old school constructor function / new keyword method, like this:
function People(name, age){
this.name = name;
this.age = age;
this.yearsUntilRetire = yearsLeft;
}
function yearsLeft(){
var numYears = 65 - this.age;
return numYears;
}
lady = new People("Lady Gaga", 28);
mickey = new People("Mickey Mouse", 99);
Now, when using this method I can create new instances of the constructor function "People" and pass in data that will fill out the values of the function (in this case, that's "name" and "age"). I'm just now learning prototypal inheritance and I get that objects inherit from other objects directly and that javascript is a classless language, for example, I know how to do the following, which I learned from a more updated tutorial:
var person = {
kind: 'person'
}
var zack = Object.create(person);
zack.kind = 'zack'
console.log(zack.kind); //=> 'zack'
// zack now has a 'kind' property
console.log(person.kind); //=> 'person'
// person has not being modified
But my question is that there doesn't appear to be any method of "passing" arguments into the constructor function to make the values of the new object more dynamic and to fill in the blueprint like is the case with constructor functions ("name" and "age") and instead it appears as though in cases where I wanted to just change the values I would just OVERWRITE the original data for some new object, like above:
zack.kind = 'zack'
At this part of the code it seems that I just stamped directly over zack.kind, which would have ended up having the value of 'person'.
Is the manipulation of values in prototypal inheritance normally done like this? Where you just stamp over the data? Or is there some method of keeping the blueprint form of a value and only passing in some select pieces of data like with constructor functions arguments? It seems strange that I don't pass data into the function but just stamp over the other objects data that you want to change (I know it doesn't change the original objects values, but it does feel a little bit loose and strange). It seems odd to me since I've been using constructor functions for a few months and want to make sure I am working the correct way. Sorry if this is a newbie question.