Javascript Namespacing

前端 未结 3 1354
遥遥无期
遥遥无期 2020-12-14 23:40

I wish to make my javascript more more modular by splitting it up into different files and giving each file a \'sub\' namespace like so.

subA.js

3条回答
  •  甜味超标
    2020-12-15 00:20

    For Questions 1 and 3:

    A closure style defenition in the ex.js will allow those public functions and vars/exposed.

    My thought is, it is better to return "ex" from the anomyous function with the functions and vars we need to expose.

    for Q3. Those ( private )variables defined and used in returned function is still avaialble to the function and can be used through the exposed function ( property of closure ).

    If the external script include is in the section or at the top of the file, the ex should be available before document.ready and should be usable straight away.

    You are making me think :) Will update the post as I dig further in to this. Very good Questions. :)

提交回复
热议问题