Skip to main content

Posts

Showing posts from November, 2019

Typescript - Self-Executing Anonymous Functions

/** * Self executing anonymous function using TS. */ (()=> { // Whatever is here will be executed as soon as the script is loaded. console . log ( 'executed' ) })(); I want a built a plugin that may work for Node.js, also for fron-tend as well. In that case you should compile your TypeScript in AMD and use an AMD loader on the frontend, like  http://requirejs.org/docs/start.html On the server side, you would need to use  requirejs  node package as well to load the file. Take a look at this:  http://requirejs.org/docs/node.html Basically there are two ways to compile TS to JS, using AMD, which is browser compliant, or using CommonJS, which is node.js compliant. Loading an AMD script in the browser or in the server needs to use an AMD compliant loader, and *requirejs** is one of them. (the most famous/used I'd say) Ref :  https://stackoverflow.com/questions/30274464/typescript-self-executing-anonymous-functions