为什么他们在导出数据或事件时不使用对象?
why they don't use Object when exporting data or event?
我正在尝试通过书籍和一些示例(如 Todos)来理解节点并做出反应。
但我从未见过他们在导出数据时使用 Object。
他们为什么不使用它?
只要我用的是Object,导出的时候就不需要添加数据或者事件了
例子
const insertUser = async (userData) => {
***
};
const loginAction = async (where) =>{
***
}
const checkDuplicationID = async (userId) => {
****
}
//you should add the event when you export event whenever events are added.
module.exports = { loginAction, insertUser, checkDuplicationID }
我的看法
let userActions = {}
userActions.insertUser = async (userData) => {
****
};
userActions.loginAction = async (where) =>{
****
}
userActions.checkDuplicationID = async (userId) => {
****
}
//you don't need to add the event when you export event.
module.exports = { userActions }
使用Object有什么问题吗?
使用对象没有问题,在javascript中,几乎一切都是对象。你可以像这样导出方法
module.exports = {
insertUser: async (userData) => {
// logic
},
loginAction: async (where) => {
// logic
},
checkDuplicationID: async (userId) => {
// logic
}
}
您可以import/require该模块并在其他模块中使用它
// import or require
const myMethods = require('./path/filename');
// call the method
myMethods.insertUser();
myMethods.loginAction();
myMethods.checkDuplicationID();
我正在尝试通过书籍和一些示例(如 Todos)来理解节点并做出反应。
但我从未见过他们在导出数据时使用 Object。
他们为什么不使用它?
只要我用的是Object,导出的时候就不需要添加数据或者事件了
例子
const insertUser = async (userData) => {
***
};
const loginAction = async (where) =>{
***
}
const checkDuplicationID = async (userId) => {
****
}
//you should add the event when you export event whenever events are added.
module.exports = { loginAction, insertUser, checkDuplicationID }
我的看法
let userActions = {}
userActions.insertUser = async (userData) => {
****
};
userActions.loginAction = async (where) =>{
****
}
userActions.checkDuplicationID = async (userId) => {
****
}
//you don't need to add the event when you export event.
module.exports = { userActions }
使用Object有什么问题吗?
使用对象没有问题,在javascript中,几乎一切都是对象。你可以像这样导出方法
module.exports = {
insertUser: async (userData) => {
// logic
},
loginAction: async (where) => {
// logic
},
checkDuplicationID: async (userId) => {
// logic
}
}
您可以import/require该模块并在其他模块中使用它
// import or require
const myMethods = require('./path/filename');
// call the method
myMethods.insertUser();
myMethods.loginAction();
myMethods.checkDuplicationID();