I am working on a stack.js application. When I try to call a static function of one of my models, I get the error message "SomeItem.createNew is not a function"
I call this static method from another static method of another circuit, for example.
Does not work:
var SomeItem = require('./some-item.js');
aSchema.statics.createNew = function(body, cb) {
var newA = new this();
for (i = 0; i < body.someItems.length; i++ {
SomeItem.createNew(body.someItems[i], function(err, item) {
}
}
Does it work:
aSchema.statics.createNew = function(body, cb) {
var newA = new this();
var SomeItem = require('./some-item.js');
for (i = 0; i < body.someItems.length; i++ {
SomeItem.createNew(body.someItems[i], function(err, item) {
}
}
However, if I put the requirement inside a static function, it works fine. Why is this? I would only like to declare “var SomeItem” only once at the top, and not in every function that I need to use.
source
share