javascript - Uncaught TypeError is not a constructor?
本文介绍了javascript - 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
想问一下这是什么原因?
解决方案
a里面没有a1
这篇关于javascript - Uncaught TypeError is not a constructor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文