Uncaught TypeError is not a constructor?

首先

function a(){    this.a1="haha";
}
b=new a();console.log(b);

可以正常运行的毋庸置疑。

那么改一下

a=function (){    this.a1="haha";
}
b=new a();console.log(b);

同样可以正常运行。

再改一下

a=function (){    this.a1=function (){        this.a2="haha";
    };
    e=new this.a1();    console.log(e);
}
b=new a();

还是可以正常运行。

但是再改一下就不行了

a=function (){    this.a1=function (){        this.a2="haha";
    };
}
b=new a();
e=new a.a1();

chrome控制台提示Uncaught TypeError: a.a1 is not a constructor

想问一下这是什么原因?


守着星空守着你
浏览 4541回答 1
1回答

侃侃无极

a里面没有a1
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript