在sails.js中组织帮助器

时间:2018-02-02 11:14:46

标签: javascript sails.js

有没有办法在sails.js v1.0中的帮助器中构造代码?

目前我有类似的东西:

doFirstThing

三个函数doSecondThing doThirdThing {{1}}各有大约15行代码。现在,代码很难阅读。有没有办法将函数放在fn函数下面或以任何其他更可读的方式构造它?

1 个答案:

答案 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
};