javascript 中面向对象編程 (类的继承)

canca canca
2007-07-01 10:10
2
0
//  人的基類
var  Person = new  (  function ()
{
  
var  sex;
  
var  name;
  
this .getSex = function ()
    
{
     
return  sex;
    }

  
this .setSex = function (value)
  
{
   sex
= value;
  }

}

);
// 學生類,需要繼承 “人”
var  Student = function  (parent)
{
    
this ._class_ = parent;
    
var  workid;
    
this ._class_.getWorkid = function ()
    
{
            
return  workid;
        }

     
this ._class_.setWorkid = function (value)
    {

        workid
= value;
    }

    
return   this ._class_;
}


  var  st = new  Student(Person);
    st.setWorkid(
" 9527 " );
     st.setSex(
" man " );
    alert(st.getSex());
    alert(st.getWorkid());

发表评论