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

后端 未结 4 1625

I saw these 2 basic ways of namespacing in JavaScript.

  1. Using object:

    var Namespace = { };

    Namespace.Clas

4条回答
  •  长情又很酷
    2020-12-08 10:59

    Well, if all you're doing us using that "Namespace" thing as a way to "contain" other names, then those two approaches are pretty much exactly the same. A function instance is just an object, after all.

    Now, generally one would use a function like that if the function itself were to be used as a constructor, or as a "focal point" for a library (as is the case with jQuery).

提交回复
热议问题