JavaScript Library Design

前端 未结 2 1735
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 21:52

I have a general question about the design of JavaScript Libraries.

I am trying to consolidate common methods into one js file so they can be reused by different scripts

相关标签:
2条回答
  • 2021-01-29 22:19

    I would recommend you to follow the Module Pattern in JavaScript instead of following JSON's pattern strictly. Your subgroup is actually referring to sub-modules. Take a look at the following excellent article:

    Ben Cherry's JavaScript Module Pattern In-Depth

    Other resources you should probably go through:

    • John Resig's Learning Advanced JavaScript
    • Seven JavaScript Things I Wish I Knew Much Earlier In My Career
    • The Seven Deadly Sins Of JavaScript Implementation
    0 讨论(0)
  • 2021-01-29 22:26

    There are problems with the module pattern. See http://snook.ca/archives/javascript/no-love-for-module-pattern. I used to use it before but stopped. Now I just tend to keep it simple. If you really want sub-namespacing you can make a simple namespace function for the job.

    See http://blogger.ziesemer.com/2008/05/javascript-namespace-function.html

    0 讨论(0)
提交回复
热议问题