当一个js函数对象被创建时,Function 构造器产生的函数对象会运行类似这样的一些代码
this.prototype={constructor:this}
新函数被赋予了一个prototype属性,它的值是一个对象,该对象包含了一个constructor属性,该属性的值为改新函数的对象
function fun(){
alert('world');
}
alert(fun.prototype.constructor==fun);//true
alert(fun.__proto__==Function.prototype)//true
alert(fun.prototype.constructor);//即为该函数对象
alert(toString.prototype.constructor);//系统自带函数,返回native code
构造函数类(首字母大写)
function Car(color){
this.color=color;
this.age=100;
}
Car.prototype.color="blue";
Car.prototype.showColor=function(){
alert(this.color);
}
alert(Car.prototype.constructor); //打印出构造函数体即函数本身对象
var car1=new Car('red');
alert(car1.__proto__==Car.prototype);//true 原型链
alert(car1.constructor);//构造函数
alert(car1.prototype);//undefined
alert(typeof car1);//obj
String 对象与字符
所有字符默认都连接到String.prototype对象上
无论是否是用new String() 创建的
var str=new String('ab'); var str1="abc"; alert(typeof str); //obj obj alert(typeof str1); //string alert(str.__proto__==String.prototype);//true alert(str1.__proto__==String.prototype);//true alert(str.constructor);//native code 说明是原生代码 底层写该函数的代码
其他基本类型一样