有没有办法在sails.js v1.0中的帮助器中构造代码?
目前我有类似的东西:
doFirstThing
三个函数doSecondThing
doThirdThing
{{1}}各有大约15行代码。现在,代码很难阅读。有没有办法将函数放在fn函数下面或以任何其他更可读的方式构造它?
答案 0 :(得分:2)
您始终可以在外部定义该功能,并在以后将其分配给您的module.exports
对象。如果不使用doFirstThing
函数的闭包变量
doEverything
和其他两个函数。
async function doEverything(inputs, exits) {
const doFirstThing = function () {
// do something
};
const doSecondThing = function () {
// do something
};
const doThirdThing = function () {
// do something
};
doFirstThing();
doSecondThing();
doThirdThing();
}
module.exports = {
friendlyName: 'Example helper that does three things',
description: '',
inputs: {},
exits: {},
fn: doEverything
};