封装
//简单理解如下:
//封装:将字段,属性,方法等封装成类
//例如:将人封装成一个类,有name,age等字段,有eat方法
function Person(name, age){
this._name = name;
this._age = age;
this.getAge = function(){
return this.age;
};
this.setAge = function(value){
this.age = value;
};
this.getName = function(){
return this.name;
};
this.eat=function()
{
alert(this._name+" Eat!");
};
}
//使用这个类:
var p1 = new Person("张三", 12);
p1.eat();