简体   繁体   English

如何在Node.js模块内部引用导出的函数

[英]How to reference an exported function inside of a Node.js module

How can I reference an exported function inside a Node.js module like: 我如何在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');

However, my linter is complaining about possible strict violation . 但是,我的小孩子抱怨possible strict violation受到possible strict violation Is there a way to do this without defining a variable? 有没有定义变量的方法吗?

When using jshint/jslint, in strict mode, 'this' that not inside a constructor function will cause 'possible strict violation'. 使用jshint / jslint时,在严格模式下,不在构造函数内部的“ this”将导致“可能的严格违反”。

Try the code below, and you will find that only thrid console.log(this) don't cause 'possible strict violation'. 尝试下面的代码,您会发现只有第三console.log(this)不会导致“可能的严格违反”。

'use strict';

console.log(this);

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM