fire
fire

Reputation: 21541

Javascript OOP subclass help and structure

I have the following code:

(function(){

    var DS = (function(){

        DS.prototype.queryDB = function() {
            alert('query database');
        };

        DS.prototype.openDB = function() {
            alert('open the database');
        };

    });

    window.DS = new DS;

})(window);

I can then call DS.queryDB() and DS.openDB() from my page which works fine.

What I want is to have a database class within DS to seperate the functions further.

I tried changing DS.prototype.queryDB to DS.prototype.Database.queryDB but that didn't seem to work. How can I best structure my code to allow for this?

Upvotes: -1

Views: 194

Answers (1)

Anil Shanbhag
Anil Shanbhag

Reputation: 968

This can be done .

Consider doing it something like this .

DS.prototype = {
    db : new Database()
}

function Database(){}

Database.prototype = {
    queryDb : function(){}
}

Upvotes: 1

Related Questions