JavaScript function declaration

前端 未结 8 802
别那么骄傲
别那么骄傲 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:19

    The first example creates a global variable (if a local variable of that name doesn't already exist) called some_func, and assigns a function to it, so that some_func() may be invoked.

    The second example is a function declaration inside an object. it assigns a function as the value of the show property of an object:

    var myObj = {
        propString: "abc",
        propFunction: function() { alert('test'); }
    };
    
    myObj.propFunction();
    

提交回复
热议问题