简体   繁体   中英

CoffeeScript main?

I'd like to have a main function that is run only if my is not imported but actually run and not imported.

Is there an equivalent to python's name == " main " in coffeescript?

Right now I'm using

is_main = process.argv[1]==__filename
if is_main
    main()

but I don't know if something more idiomatic exists, and I noticed it did not work with older versions of coffeescript.

Related JS question

main() if require.main is module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM