javascript 中面向对象编程 (类的构造)

canca canca
2007-07-01 10:23
3
0



EmcObj = function (w,h)
{
 
this .xWidth = w;
 
this .yHeight = h;  // this 表類私有變量
}

EmcObj.prototype._Init = function ()
{
 
this .config = {
                render : 
" AUTO " ,
        linkType : 
" M " ,
        linkColor : 
" blue " ,
        nodeColor : 
" #CCCCFF " ,
             }
;
// 獲取此屬性值用:this.config.nodeColor 
}
ECOTree.prototype.toString  =   function  ()  {    
    
var  sl  =  [];
    sl.push(
" <div name=abc> " );
    sl.push(
" </div> " );    
    
return  sl.join('');
}


this .config.name = " aa " ; // 這樣就行了

var  emc
function  CreateEmcObj()
{
 emc
= new  EmcObj( 100 , 100 );
 document.write(emc.tostring());
}


function  CreateInit()
{
 emc._init();
}

发表评论