Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

a simple question #87

Open
zzz6519003 opened this issue May 31, 2015 · 2 comments
Open

a simple question #87

zzz6519003 opened this issue May 31, 2015 · 2 comments

Comments

@zzz6519003
Copy link

React = window.React;
delete window.React;

wondering what this does 🍻

@froatsnook
Copy link
Contributor

@zzz6519003 Uhh, maybe some of this is wrong, but I'm pretty sure it works as follows.

In short:

  1. react.js assigns React to window
  2. React = window.React; makes a package-wide variable which is later exported
  3. delete window.React; removes the window variable "leak"

Most of this package defines React in: vendor/react-with-addons-0.13.0.js. This creates window.React.

Normally in Meteor apps:

// This is local to the current file
var ABC = function() { };

// This is globally available in the APP
XYZ = function() { };

But in packages:

// This is local to the current file
var ABC = function() { };

// This is globally available in the PACKAGE
XYZ = function() { };

In order to make a package global variables available in apps that include the package, you take one of these XYZ variables and export it in package.js.

So now to answer your question:

When you say:

XYZ = function() { }; // (i.e. without var)

It assigns to this, which normally happens to be window in the browser. But in a package, it is assigned to something else (for package-wide variables). Assigning React to window would be "bad" because if you didn't export it in package.js it would be visible by apps anyway.

@zzz6519003
Copy link
Author

so long story short, it just wanna make it clean, just a good habit? thx buddy! 🍺

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants