Is 'event' a reserved word in JavaScript?

前端 未结 6 1885
谎友^
谎友^ 2020-12-09 01:47

I am a beginner to Javascript. And when I was practicing I have noticed something.

Take this function:



        
6条回答
  •  执念已碎
    2020-12-09 02:20

    Well, the code:

    onkeypress="return showChar('some text', oEvent);"
    

    Is the equivalent of the following JavaScript code:

    element.onkeypress = function (eventObjectName) {
        return showChar('some text', eventObjectName);
    };
    

    It's just that browsers name the event argument as event.

    So, the value of the attribute is wrapped in a JS function which receives an argument named event which is the event object.

提交回复
热议问题