Javascript - difference between namespace vs. closure?

前端 未结 3 499
无人共我
无人共我 2021-02-02 03:34

In Javascript, what\'s the difference between a namespace and a closure? They seem very similar to me.

EDIT

Specifically, this article discusses namesp

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 04:05

    From http://jibbering.com/faq/notes/closures/:

    A closure is formed by returning a function object that was created within an execution context of a function call from that function call and assigning a reference to that inner function to a property of another object. Or by directly assigning a reference to such a function object to, for example, a global variable, a property of a globally accessible object or an object passed by reference as an argument to the outer function call.

    Namespaces are just a convention, objects created to avoid cluttering the global scope with variables.

提交回复
热议问题