Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to inherit in JSON?

Status
Not open for further replies.

dkdude

Programmer
Jun 16, 2003
849
DK
Hi,

So, I got this object

Code:
var myObj = {
  init : function() {
           this.name = 'Master!';
           this.run();
         } ,
  run : function() {
    alert('Hello '+this.name);
  }
}

It works just fine. Now I would like to make a new object (JSON) that expands myObj.

How do I do that? If it can be done.

Thanks
 
Okay, so I got a bit further. This seems to be working:
Code:
baseJSON = function() {
                 var F = function() {
               };
               return F;
           }
               

myJSON = baseJSON();


myJSON.prototype = {
  init : function() {
           if(arguments.length>0)
             this.name = arguments[0];
           else
             this.name = 'Master - you forgot to initialize with your name!';
           this.run();
         } ,
  run : function() {
    alert('Hello '+this.name);
  }
}


var newObj = new myJSON();

How can I make a new protype on top of myJSON, that will inherit the (prototyped) methods (and properties, if applicable) from myJSON?

Any ideas? I'm quite new to JSON, so please forgive my ignorence ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top