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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -