javascript- Uncaught SyntaxError: Identifier * has already been declared

前端 未结 3 1554
盖世英雄少女心
盖世英雄少女心 2020-12-24 07:52
console.log(a) //output:ƒ a(){}
var a = 1;
function a(){};
var a = 10;
console.log(a) //output:10

====================

var a = 1;
i         


        
3条回答
  •  天命终不由人
    2020-12-24 08:26

    The simple solution to this is to use IIFE

    (function() {
    var sahil = {
      checkThis: function() {
        console.log(this);
    
        function checkOther() {
          console.log(this);
        }
        checkOther(); // checkThis() function called in "global context", will
                      // return "this" as "window"
      }
    };
    var moo = sahil.checkThis;
    moo(); // moo() function called in "global context", will return "this" as "window" })();
    

提交回复
热议问题