开发者

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.prototy开发者_开发问答pe.Database.queryDB but that didn't seem to work. How can I best structure my code to allow for this?


This can be done .

Consider doing it something like this .

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

function Database(){}

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜