`if __name__ == '__main__'` equivalent in javascript es6 modules

后端 未结 3 2033
猫巷女王i
猫巷女王i 2020-12-04 01:53

Is it possible to check if JavaScript file is being run directly or if it was required as part of an es6 module import.

for example a main script is included.

<
3条回答
  •  攒了一身酷
    2020-12-04 02:27

    The solution I see there is just to define the variable in the script you're importing. I.e. you define mainTest in main.js, and then use your existing if block.

提交回复
热议问题