Error on using alert in Javascript (Property 'alert' of object is not a function)

后端 未结 6 588
北恋
北恋 2021-01-11 12:59

I am just trying to use alert and put a string variable inside the alert and get an error:

Uncaught TypeError: Property \'alert\' of object [Object Window] i         


        
6条回答
  •  清酒与你
    2021-01-11 13:27

    Adding to Chris's answer... I had mistakenly overrode alert in my own function!

        //Don't do this:
        function alertOrConsole(node, alert){
            if(alert){
                alert(node);
            }else{
                console.log(node);
            }
        }
    

       //----------------------------
       //Fixed:
        function alertOrConsole(node, flag){
            if(flag){
                alert(node);
            }else{
                console.log(node);
            }
        }
    

提交回复
热议问题