JavaScript 学习之 -- 继承方式:对象冒充

function ClassA (sColor) {
  this.color = sColor;
  this.sayColor = function () {
  alert(this.color);
  }
}

function ClassB (sColor,sName) {
  this.newMethod = ClassA;
  this.newMethod (sColor);
  delete this.newMethod;

  this.name = sName;
  this.sayName = function () {
  alert(this.name);
  }
}

var objA = new ClassA("red");
var objB = new ClassB("blue","Nicholas");
objA.sayColor();
objB.sayColor();
objB.sayName();

//red

//blue

//Nicholas

posted @ 2013-06-05 11:37  Earic  阅读(132)  评论(0编辑  收藏  举报