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.
Written by Martin Aspeli
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#