Difference between class(java) and closure(javascript)?

后端 未结 5 2082
别那么骄傲
别那么骄傲 2020-12-15 13:14

I don\'t understand how closure is more powerful than class. It looks like I can achieve the same behavior of closure using class. Any help would be appreciated

5条回答
  •  清歌不尽
    2020-12-15 13:46

    A closure and a class are two very different things.

    It is not correct to say 'A class is more powerful that a closure.' or vise a versa.

    They do totally different things.

    A closure is in a basic sense, a function call that retains the local variable information from the scope it was created.

    A class is a definition of an object. The class defines behavior and the contents of instances of the class.

提交回复
热议问题