JavaScript function declaration

前端 未结 8 1001
别那么骄傲
别那么骄傲 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...

    some_func = function(value) {  
        // some code here
    }
    

    is declaring a variable and assigned an anonymous function to it, which is equivalent to...

    function some_func (value) {  
        // some code here
    }
    

    The second one should look like this...

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

    and equivalent to...

    //pseudo code
    class MyClass {
        function show (value) {
            // some code here
        }
    }
    obj = new MyClass();    // obj.show(value)
    

    Cheers

提交回复
热议问题