【发布时间】:2019-03-16 23:02:06
【问题描述】:
是否可以在需要时调用 Node.js 模块中的函数。
app.js
const Database = require('./database').Database;
const UsersModel = require('./model').Model; // pass the name = Users and database
const AdminsModel = require('./model').Model; // pass the name = Admins and database
数据库.js
export class Database {
// some functions here
}
model.js
export class Model {
onModelCreated(name, database) {
this.name = name;
this.database = database;
}
insert() {}
find() {}
delete() {}
update() {}
}
【问题讨论】:
-
你的意思是一次还是每次在某个地方需要它?你想达到什么目的?这听起来像是一个 XY 问题...
标签: javascript node.js node-modules