kaniosrn-j
2/28/2018 - 8:24 PM

Creating Objects: Object.create

The benefits of using object.create() is allow you implement a complex inheritant structure in an easier way than a constructor. This allows you to directly specify which object should be a prototype.

/////////////////////////////
// Object.create
var personProto = {
    calculateAge: function() {
        console.log(2016 - this.yearOfBirth);
    }
};

var john = Object.create(personProto);
john.name = 'John';
john.yearOfBirth = 1990;
john.job = 'teacher';

var jane = Object.create(personProto, {
    name: { value: 'Jane' },
    yearOfBirth: { value: 1969 },
    job: { value: 'designer' }
});