Is “clear” a reserved word in Javascript?

后端 未结 4 1879
粉色の甜心
粉色の甜心 2020-11-22 02:15

I just spent a long time figuring out that I shouldn\'t use clear() as the name of a function in Javascript:


    

        
4条回答
  •  独厮守ぢ
    2020-11-22 02:59

    Not according to the MDN.

    Edit:

    You got me curious, so I threw together this little jsfiddle.

    function clear() {
        alert("you cleared just fine");
    }
    
    $('clear').addEvent('click', clear);
    

    Having a function named clear seems to work just fine.

提交回复
热议问题