復制代碼 代碼如下:
//重新封裝document對象
var Console={
Write:function(msg){alert(msg);}
};
//Person對象
var Person={
_name:"zzl", //static public
_age:28,
PrintInfo:function(){Console.Write("name:"+Person._name+",age:"+this._age);} //public method ,this表示Person
};
// People類型(對象)
var People=(function()
{
var _name="zzl";//private
var _age=28;
return {//public
PrintInfo:function(){Console.Write("name:"+_name+",age:"+_age);}
}
}
());
Person.PrintInfo();//對象中的方法
People.PrintInfo();//方法對象中的公開子方法
Console.Write(Person._name);//對象中的屬性