What is the difference between a function call and function reference?

前端 未结 6 2346
别跟我提以往
别跟我提以往 2020-11-22 05:50

I have the following function

function hello() {
 alert(\"hi!\");
}

Take this piece of code:

var elem = document.getElem         


        
6条回答
  •  抹茶落季
    2020-11-22 06:16

    A reference to your function is needed somewhere no matter how it gets called. The difference here is that you are not explicitly calling the hello function. You are assigning a reference to that function to the elem DOM node's onclick event handler so that when onclick is fired for that Node, your function gets called.

提交回复
热议问题