//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);

 

相关文章:

  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2021-02-22
  • 2022-12-23
  • 2021-05-13
  • 2021-06-18
  • 2022-12-23
猜你喜欢
  • 2022-01-09
  • 2021-09-08
  • 2021-10-03
  • 2021-09-13
  • 2019-03-15
  • 2021-05-20
相关资源
相似解决方案