如何在Node.js模块中引用导出的函数,如:
'use strict';
const orm = require('orm');
module.exports = orm.createModel('Accounts');
const Project = require('./Project.js');
// this should be the result of orm.createModel('Accounts')
this.hasMany(Project, 'projects');
然而,我的短信抱怨possible strict violation
。有没有办法在不定义变量的情况下做到这一点?
答案 0 :(得分:1)
当使用jshint / jslint时,在严格模式下,不在构造函数中的'this'会导致'可能严格违规'。
尝试下面的代码,您会发现只有第三个console.log(this)
不会导致'可能严格违规'。
'use strict';
console.log(this);
function test() {
console.log(this);
}
function Test() {
console.log(this);
}