javascript里new构造函数返回的值

var a = new XXX();

a是什么?
要分类讨论
一:
function XXX(){
    return 原始类型(数字,字符串,bool,null,undefined)
}
则a是new出来的对象

二:
function XXX(){
    return 引用类型
}
则a是这个return的值

如:
function XXX(){
    this.y = 10;
    return {
        x:1
    }
}

var a = new XXX();
console.log(a.x); //1
console.log(a.y); //undefined  


再如:
function XXX(){
    this.y = 10;
    return function aaa(){}
}

var a = new XXX();
console.log(a); //aaa()
console.log(a.x); //undefined

原文地址:https://www.cnblogs.com/phper007/p/3456037.html