Reputation: 51253
Why does the following code complain that Model
is undefined?
// models/person.js
Model = Model || {}; // ReferenceError: Model is not defined.
_.extend(Model, {
Person: function(name) {
this.name = name;
}
});
var adam = new Model.Person("Adam");
Upvotes: 0
Views: 80
Reputation: 51253
Based on Akhlesh answer.
I create a file defining share
:
// lib/_share.js
if (Meteor.isClient) {
share = window;
}
if (Meteor.isServer) {
share = global;
}
And then this works:
// models/person.js
Model = share.Model || {};
Upvotes: 1
Reputation: 2399
Actually you should check for Model as window's property or use var.
Model = window.Model || {};
OR
var Model = Model || {};
Upvotes: 0
Reputation: 23692
This issue occurs in strict mode.
Try this:
var Model;
Model = Model || {};
the documentation on strict mode: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode#Converting_mistakes_into_errors
Upvotes: 0