How can I pass arguments to anonymous functions in JavaScript?

前端 未结 10 1459
别那么骄傲
别那么骄傲 2020-12-08 01:37

I\'m trying to figure out how to pass arguments to an anonymous function in JavaScript.

Check out this sample code and I think you will see what I mean:



        
10条回答
  •  甜味超标
    2020-12-08 02:17

    What you have done is created a new anonymous function that takes a single parameter which then gets assigned to the local variable myMessage inside the function. Since no arguments are actually passed, and arguments which aren't passed a value become null, your function just does alert(null).

提交回复
热议问题