On Wed, Nov 16, 2011 at 7:37 AM, Rahul <rahulshivsha...@gmail.com> wrote: > (function(){ > > var personProto = { > describe : function(){ > alert("NAME IS "+this.name); > } > }; > > var jane = { > name : "JANE", > __proto__ : personProto > }; > > var tarzan = { > name : "TARZAN", > __proto__ : personProto > }; > > jane.describe(); > > > })(); > > in the above code for the last line i am getting an error "Object > doesn't support this property or method",
In which browser? IE doesn't support the non-standard __proto__ property. > But what i am expecting is object "jane" must inherit method describe > from object "personProto" In ES5 browsers use: var tarzan = Object.create(personProto); tarzan.name = "TARZAN"; or var tarzan = Object.create(personProto, {name:{value:"TARZAN", writable:true, configurable:true,enumerable:true}}); In older browsers you can make your own equivalent to Object.create: function clone(o) { function_(){}; _.protototype = o; return new _; } var tarzan = clone(personProto); tarzan.name = "TARZAN"; Or, just do it the old-fashioned way: function mkTarzan() { this.name = "TARZAN"; } mkTarzan.prototype = personProto; var tarzan = new mkTarzan(); What is the problem you are trying to solve that don't work with normal constructor functions? /L -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com