Method vs Functions, and other questions

前端 未结 8 1660
梦毁少年i
梦毁少年i 2020-11-27 13:26

With respect to JS, what\'s the difference between the two? I know methods are associated with objects, but am confused what\'s the purpose of functions? How does the syntax

8条回答
  •  醉话见心
    2020-11-27 13:47

    There is a slight difference -

    Method : Method is a function when object is associated with it.

    var obj = {
    name : "John snow",
    work : function someFun(paramA, paramB) {
        // some code..
    }
    

    Function : When no object is associated with it , it comes to function.

    function fun(param1, param2){
    // some code...
    }
    

提交回复
热议问题