Last Updated: February 25, 2016
· optilude

Meteor namespacing

Goal: Have use strict and JSHint work in Meteor apps that need to share models between two or more files.

Firstly, create lib/_namespaces.js like this:

/* global Models: true, Collections: true */

// This file exists so that we can do "use strict" in all other files and
// still have some global namespace variables.

// It's called what it's called and placed where it's placed so that it loads
// as early as possible.

Models = {};
Collections = {};

Note that this doesn't contain "use strict", and we have told JSHint that we intend to write to two globals, Models and Collections.

From now on, we can do things like:

/* global Collections, Models */
"use strict";

Collections.Foo = new Meteor.Collection("Foo");

Obviously, Models and Collections are just examples.