2016-09-19 65 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); 
} 
相關問題