What’s the difference between using objects and functions for namespacing in Javascript?

后端 未结 4 1608

I saw these 2 basic ways of namespacing in JavaScript.

  1. Using object:

    var Namespace = { };

    Namespace.Clas

4条回答
  •  再見小時候
    2020-12-08 11:15

    The first one declares a simple object while the second one declares a function. In JavaScript, functions are also objects, so there is almost no difference between the two except that in the second example you can call Namespace() as a function.

提交回复
热议问题