标签:cto console lang tle blank .com 创建 对象 return语句
//1.几乎所有函数都有prototype属性,这个是个指针,指向原型对象;Function.prototype这个没有//2.所有对象中都有__proto__属性.(Object.prototype该属性的值为null)//几乎所有函数都有 prototype/__proto__属性//3.函数都是Function的实例(函数是通过Function创建出来的对象)//自定义函数,Function,Array,RegExp,String,Boolean,Number,Object都是函数,都是通过Function创建出来的//4.几乎所有函数都继承自:Function.prototype//函数.__proto__===Function.prototype(除了Function.prototype本身,他没有prototype属性)//Object.__proto__===Function.prototype//Function.__proto__===Function.prototype//5.String.prototype.__proto__===Object.prototype// Array.prototype.__proto__===Object.prototype// Number.prototype.__proto__===Object.prototype// RegExp.prototype.__proto__===Object.prototype// Function.prototype.__proto__===Object.prototypefunction fn(){returnthis;}var f3=new fn();console.log(f3);//fn//return {name:"张三"};//此时构造函数的返回值是一个对象就不再使用默认的返回值了,返回值就是当前的对象function fn2(){}var f2 =new fn2();console.log(fn2);//fn2的实例//如果没有返回值,会是默认的返回值//如果返回值是基本数据类型的话,还是会使用默认的返回值function fn(){} console.log(fn.constructor);//Function console.log(fn.__proto__===Function.prototype);//true console.log(Object.__proto__===Function.prototype);//true console.log(Function.prototype===fn.__proto__);//true console.log(Object.constructor);// Function console.log(fn.prototype.constructor);//fn console.log(Function.prototype.__proto__.constructor);// Objectvar arr=["hello","say","pic"];var str3;//undefinedfor(var i=0;i<arr.length;i++){ str3+=arr[i];//如果一个变量str3声明了没有赋值会有默认的值undefined如果参与运算的话就会出问题//所以以后再声明变量之后要给初始化的值}console.log(str3);//undefinedhellosaypicconsole.log(undefined+"abc");//变为一个字符串undefined abc标签:cto console lang tle blank .com 创建 对象 return语句
原文地址:http://www.cnblogs.com/itlyh/p/6012150.html