function Human(){
this.height=180;
this.say=function(){
alert("我在说话");
}
}
var he = new Human();
alert(Human.prototype);//Object Object
alert(he.prototype); //undefined
prototype是构造器/函数才具有的属性
JavaScript内置的构造器有以下几个:
Object,Number,Boolean,String,Array,RegExp,Date,Function,Error,Math,JSON等,
其中Math和JSON是以对象形式存在的,无需new便可创建。当我们用 var mm=new Math(1234565);的时候,会报错。
Object,Number,Boolean,String,Array,RegExp,Date,Function,Error的原型是Function.prototype。而Math和JSON对象的原型是Object.prototype。
也就是说,Javascript中,只有上述的对象有prototype属性,其它的通过这些构造器创建的对象,都没有这个属性。
1、 he 是 Human的一个实例化对象 ( typeof he = “object” ),但是不是一个函数,所以没有prototype;Human是Function的一个实例,而Function是一个函数,他的实例Human也是一个函数 ( typeof Human = “function” ),所以他们都有prototype。此外Object Array RegExp等也是函数。Math就仅仅是一个new Object() ,不是函数。
2、构造函数的prototype,默认情况下就是一个new Object()还额外添加了一个constructor属性。所以说默认是没有prototype只有__proto__的。