Variable area when recording meteor packet

When I wrote the js file in the meteor package, I had the following codes:

A = 1;
console.log(A);
console.log(window.A);

I am wondering why the first console.log prints 1 and the second prints undefined.

+4
source share
2 answers

This is because it bundlerintelligently understands your source code for a package that searches for global variables.. In the end, the (generated) code of your package (i.e. the one that actually loads into the browser) precedes something like:

/* Package-scope variables */
var A;

which should open everything;)

, , , @sbking, package.js :

// was Package.on_use in older Meteor versions
Package.onUse(function (api) {
  api.export('A');
});

, use strict , Meteor , api.export. , , .

, , , undefined , . .

use strict :

// globals.js
// no "use strict" statement here ...
MyPrivateVariable1 = null;
MyPrivateVariable2 = null;
+5

Source: https://habr.com/ru/post/1536552/


All Articles