weird part 63 — object.create and pure prototypal inheritance
1 min readNov 21, 2018
#Object.create()
var person = {
firstname : 'Default',
lastname: 'Default',
year : 1984,
age : function(){
return 2018 - this.year;
},
greet : function(){
return 'hello ' + this.firstname;
}
}var john = Object.create(person);
console.log(john)john.firstname = 'John';
john.lastname = 'Doe';
console.log(john.greet())
console.log(john.age())
- Object.create(prototypeObject, propertyObject)
# comparison with function constructor
const Person = function(firstname, lastname, year){this.firstname = firstname;
this.lastname = lastname;
this.year = year;
}Person.prototype.getAge = function(){
return 2018 - this.year;
}const april = new Person('April','kang', 1984)
const john = Object.create(Person.prototype);console.log(april)
console.log(john)
#reference
http://techsith.com/home/object-oriented-programming-javascript/