JavaScript function declaration

前端 未结 8 955
别那么骄傲
别那么骄傲 2021-01-30 04:49

Are the JavaScript code snippets given below some sort of function declaration? If not can someone please give an overview of what they are?

some_func = function         


        
8条回答
  •  渐次进展
    2021-01-30 05:03

    The first one is simply creating an anonymous function and assigning it to a variable some_func. So using some_func() will call the function.

    The second one should be part of an object notation

    var obj = {
      show:function(value){
        // some code here
      }
    };
    

    So, obj.show() will call the function

    In both cases, you are creating an anonymous function. But in the first case, you are simply assigning it to a variable. Whereas in the second case you are assigning it as a member of an object (possibly among many others).

提交回复
热议问题