Understanding module design pattern in javascript

后端 未结 2 1050
-上瘾入骨i
-上瘾入骨i 2021-01-17 03:41

I am not very good in JavaScript. so when I saw a block of code now then many area is not clear. So someone please help me to understand.

I know this below way peopl

2条回答
  •  无人共我
    2021-01-17 03:55

    1) what is this code var HMS = HMS || {}; ?

    If HMS is undefined HMS is to be equal to an empty object otherwise use HMS as is (in your case HMS is an object).

    2) see this $(function () {}) ();

    It's called IIFE.

    3) why like HMS.PatientModel = function () { };

    HMS is an object and just adding its property with value. Value may be anything.

    4) From your comment in another answer, why they didn't define module name?

    They have defined the module name as Module. See var Module = (function(){}());

提交回复
热议问题