Error in implementing Inheritance in javascript -
var old = {name:'abc',id:'3'}; new = object.create(old); alert(new.name);
i trying run simple example not working. can wrong?
edit: made mistake taking reserved keyword variable name, please dont kill me that. happens.
the following makes sense :
var parent = {name:'abc',id:'3'}; child= object.create(parent ); child(new.name);
for other user landing here searching inheritance in javascript in javascript inheritance achieved linking object other shown above. when use variable, javascript engine search variable in current object , if not find it, linked object , value there.
thanks. cheers!!
new
keyword.
you need update from
new = object.create(old); alert(new.name);
to
var x = object.create(old); alert(x.name);
Comments
Post a Comment