JavaScript原型链demo

function Person(name){
  this.name = name;
}

Person.prototype = {
  say: function(){
    alert('hi');
  },
  sayName: function(){
    alert(this.name);
  }
};

function Programmer(){
  this.say = function(){
    alert('im Programmer, my name is ' + this.name);
  }
}

Programmer.prototype = new Person('mikej');
//手动修正构造函数
Programmer.prototype.constructor = Programmer;
var p1 = new Programmer();

console.dir(Programmer.prototype.constructor);//Programmer
console.dir(p1.constructor);//Programmer
console.dir(p1);

  

posted @ 2015-03-21 20:20  yo胡yo  阅读(231)  评论(0编辑  收藏  举报