JS 中 try catch 引起的无参错误

先上个代码

function Animal() {
    console.log("Animal");
}

function Person() {
    console.log("Person");
    try{
        this.animalInstance = new Animal();
    }catch(){
        console.log("new Animal failed");
    }
    console.log("Person done");
}



 var male = new Person();

只会打印出一个错误:Uncaught SyntaxError: Unexpected token )

因为红色括号内没有参数。

从逻辑上看先会打印出Person 后才会打印出这个错误:Uncaught SyntaxError: Unexpected token )

为什么呢?

还是有Webstom 写代码靠谱,会帮助你检查代码错误,避免低级错误,节约时间。

猜你喜欢

转载自blog.csdn.net/liubangbo/article/details/84244558
今日推荐