I’m following along with “Javascript: Understanding the Weird Parts”, which is awesome, but I’m a little confused with something in the Objects section.
The author presents these ideas:
//Ex: A
var Person = {
fname: 'DEFAULT';
lname: 'DEFAULT';
}
var John = Object.create(Person);
john.fname = 'John';
john.lname = 'Doe';
//Ex: B
function Person(first, last) = {
fname: first;
lname: last';
}
var john = new Person('John', 'Doe);
The author seems to indicate a preference for the Object.create method over the ‘new’ method, but my question is: what’s the advantage? If in the creation of John I have to, one at a time, manually overwrite each of the properties in Person, what do I gain by having created Person? Especially in the case of a complex object with lots of properties. It seems like the constructor functions would be more efficient and create fewer chances of me making an error while dealing with multiple objects. In either case, you can stick methods on the prototypes. What is a reason one would use Object.create over ‘new Whatever()’?