hi friends,

i went through "Douglas Crockford" book "Javascript : The good parts"

and i rearranged the code as below and it worked,


(function(){

        var personProto = {
                describe : function(){
                         alert("NAME IS "+this.name);
                }
        };

        if(typeof Object.createObj !== 'function'){
                Object.createObj = function(protoOfObj){
                        var F = function(){};
                        F.prototype = protoOfObj;
                        return new F();
                };
        }

        var jane = Object.createObj(personProto);
        jane["name"] = "JANE";

        var tarzan = Object.createObj(personProto);
        tarzan["name"] = "TARZAN";

        jane.describe();
        tarzan.describe();

})();


Thoughts on it please ,

waiting for the reply


On Nov 16, 1:20 pm, Rahul <rahulshivsha...@gmail.com> wrote:
> i removed the line
> __proto__ : personProto
>
> from both the object jane and tarzan, and i added
>
> Object.getPrototypeOf(jane) = personProto;
> Object.getPrototypeOf(tarzan) = personProto;
>
> but still at line
> jane.describe();
> i gives an error that "Object doesn't support this property or method"
>
> On Nov 16, 12:15 pm, Anoop Gupta <gupta.anoop.ku...@gmail.com> wrote:
>
>
>
>
>
>
>
> > _prop_  property is deprecated and should not be used in new code: use
> > Object.getPrototypeOf<https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/...>
> > instead.
> > Anyways this code is working.
> > tried it onhttp://jsfiddle.net/anoop/HfsKC/
>
> > -AG
>
> > On Wed, Nov 16, 2011 at 12:07 PM, 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",
>
> > > But what i am expecting is object "jane" must inherit method describe
> > > from object "personProto"
>
> > > can anyone please help me out
>
> > > --
> > > To view archived discussions from the original JSMentors Mailman list:
> > > http://www.mail-archive.com/jsment...@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
>
> > --
> > Regards
> > Anoop K. Gupta

-- 
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

Reply via email to