Function declarations should not be placed in blocks. Use a function expression or move the statement to the top of the outer function

前端 未结 2 1283
长情又很酷
长情又很酷 2020-12-16 13:13

I have the following code:

if (typeof console === \"object\" && typeof console.error === \"function\") {
    function e(msg) {\"use strict\"; console         


        
2条回答
  •  自闭症患者
    2020-12-16 13:46

    You should not be creating function inside if block. You are much better off doing:

    var e = function(){};
    
    if(typeof console === "object" && typeof console.error === "function"){
        e = function (msg){ ... };
    }
    

提交回复
热议问题