2016-09-19 91 views
0

如何我可以引用导出功能的Node.js的模块内,如:如何引用导出函数的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

前5行是'。/ Project.js'的内容吗?我不理解你的问题和你的文件结构。 – MinusFour

+0

不,它是'./ Account.js'。基本上试着去做'const Account = orm.createModel('Accounts');'然后'module.exports = Account;'。 – Justin

+1

那有什么问题? – MinusFour

回答

1

当在严格模式下使用jshint/jslint时,不在构造函数内部的'this'会导致'可能的严格违规'。

试试下面的代码,你会发现只有第console.log(this)不会导致'可能严重违反'。

'use strict'; 

console.log(this); 

function test() { 
    console.log(this); 
} 

function Test() { 
    console.log(this); 
}