I am new to JS.
I was experimenting in JSFiddle.
I have created an object A and then I have created two new Objects B and C like below.
debugger;
var A = {
name:"h",
lastname:'n',
address:'B'
};
A.getname = function()
{
console.log(this.name);
};
var B = Object.create(A);
var C=new Object();
C.prototype = A;
console.log(B.lastname);
console.log(C.lastname);
A.getname();
B.getname();
C.getname();
I have taken the concept of creating a new object with already existing object using Object.create(old object) from javascript:Good Parts book and the concept of inheriting object from http://www.codecademy.com/courses/objects-ii/3/3?curriculum_id=506324b3a7dffd00020bf661 .
After debugging, But I the value console.log(C.lastname) is undefined and C.getname() is giving me error.
TypeError: C.getname is not a function
Why is it throwing me error and what are the advantages of using Object.create() in this case.