constrcutor

/**
 * 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

  

posted @ 2015-05-11 22:00  菠萝君  阅读(235)  评论(0编辑  收藏  举报