一个奇怪的语法错误

为什么报 Uncaught TypeError: console.log(...) is not a function?而另两种方式可以

var x = {

        fn: function () {

            console.log(this)

//            !function () {

//                console.log(this)

//            }();//正确

            (function () {

                console.log(this);

            })();//Uncaught TypeError: console.log(...) is not a function

        }

    };


    (function () {

        console.log(this);

    })();//正确


    x.fn()


慕的地6264312
浏览 453回答 1
1回答

猛跑小猪

因为第三行的 console.log(this) 没有加分号可以简单的运行以下代码,会报同样的错误:console.log(1)(2); // Uncaught TypeError: console.log(...) is not a function
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript