/** * Created by Administrator on 2015/5/11. */ var Super = function(){ }; Super.prototype.sayHello = function(){}; var Sub = function(){ Super.call(this); }; Sub.prototype = new Super(); Sub.prototype.constructor = Sub;//为什么要指回来? //因为Sub.constructor变成了Super, // 构造函数如果需要辨别自己是谁构造出来的,就需要指回来 Sub.prototype.subSayHello = function(){}; var sub = new Sub(); var s = new Super(); sub.constructor === Sub //true sub.constructor === Super //false sub.__proto__ instanceof Super //true sub.__proto__ instanceof Sub //false
时间: 2024-10-14 21:54:29