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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSON objects and inheritance?

Status
Not open for further replies.

dkdude

Programmer
Jun 16, 2003
849
DK
Okay, so I'm new to JSON. Did some reading and got exited. Look both easy and looks like what I need.

I've written a dynamic absolute-div-"windowing system" for my own web appilcation. Works great.

Now to get the thing to work the way I intend, here's what I plan to do to "fill" those windows:

AJAX the data-content AND css/xhtml formatting object into my windows -both as JSON.

As far as I can see, this can be done with AJAX -do correct me if I'm wrong?!

This is the way I found to extend a base class. It works, but doesn't seem all that good and it doesn't really accomplish what I am looking to do:

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();

Is this the right/only way to extend/inherit from superclasses in JSON?

QUESTION : Can I prototype "on top" of my "myJSON" prototyped object? The goal is to create generic classes to be AJAXed...

Any advice is greatly appreciated. Links, books whatever you see fit ;-)

Thanks
 
Take a look at the Prototype library's "Extend" syntax - it's a great way of inherting (although by no means the only way).

P.S. If you need further help with inheritance / JSON, I'd ask in the JavaScript forum (forum216) - it's not really got anything to do with AJAX (apart from the end result)...

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top