//构造函数中,如果返回的是一个对 象,那么就保留原意. 如果返回的是非对象,比如数字、布尔和字符串,那么就返回 this,如果没有 return 语句,那么也返回this.
var myFun1 = function(){
this.name = "LiuYashion1";
self1 = this;
return 'BOY'
}
var myFun2 = function(){
this.name = "LiuYashion2";
return {
sex:'BOY'
};
}
var temp1 = new myFun1();
var temp2 = new myFun2();
console.log(temp1); //myFun1 {name: "LiuYashion1"}
console.log(temp1.name); //LiuYashion1
console.log(temp2); //Object {sex: "BOY"}
console.log(temp2.name); //undefined
console.log(temp2.sex); //BOY
console.log(myFun1()); //BOY
console.log(myFun2()); //Object {sex: "BOY"}