//Apple构造函数
function Apple(color,weight,home) {
    //设置属性的值
    this.color=color;
    this.weight=weight;
    this.home=home;
    this.price = new Array(12,15); //[12,15];
    if(typeof Apple.created == "undefined") {
        //添加一个方法  这种方法 确保 定义的方法 只构造一次 而不会每次实例化都定义一次
        Apple.prototype.showHome=function() {
            alert(this.home);
        }
        Apple.created = true;
    }
}
//创建一个Apple对象
var objApple1 = new Apple("red",30,"china");
//添加一个价格
objApple1.price.push(23);
 
                    
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号