Fred J.
Fred J.

Reputation: 6049

Meteor "use strict" with global alias

In another SO post here, the second option is to write G.this; in the first "top" file in order to create a namespace.
And then write "use strict" on the top of every other js file.

Is that all the content of such a file? and if so, where the "top" file should be located (server, client, both) and what name? as Meteor loads files based on their paths. Thanks

Upvotes: 2

Views: 122

Answers (1)

Soubhik Mondal
Soubhik Mondal

Reputation: 2666

One of ways to create a global namespace in Meteor (as suggested in the SO answer) is to have a file where a global alias to this is declared, such as:

G = this;

This file should, ideally, be loaded first and on both client and server.

To achieve this, according to the doc:

  1. Files within lib/ directory are loaded first (after loading template files on client).
  2. Meteor will load any file outside client/ or server/ directories on both client and server.
  3. Where no other rules may apply, alphabetical ordering of the paths is used to determine load order of the files.

So, in keeping with these rules I would save the file as app.js (or any similar name that would come first alphabetically). Then I would place this file at the root of lib/ folder so that it gets loaded both on client and server.

So, the path to app.js would be : ./your_meteor_project_root/lib/app.js

Upvotes: 1

Related Questions