gpt4 book ai didi

node.js - 如何在CompoundJS中通过 "use"方法传递参数?

转载 作者:太空宇宙 更新时间:2023-11-03 22:18:01 25 4
gpt4 key购买 nike

我正在使用CompoundJS(用于 Express/NodeJS 的 MVC)。在 Controller 之间共享代码 the Doc sayscontroller1.js 上,我可以使用 publish 方法共享一个方法:

/***controller1.js***/
function sharedFunction () {...}
publish('sharedFunction', sharedFunction); //Sharing...

controller2.js 中,我可以通过加载并尝试use方法来访问它:

/***controller2.js***/
load('controller1'); // _controller siffix must be omitted
use('sharedFunction')

问题

这很好用,但是,我有一个带有参数的 sharedFunction:

/***controller1.js***/
function sharedFunction (param1, param2) {...}
publish('sharedFunction', sharedFunction); //Sharing...

我一直在阅读文档,但是我找不到如何或语法在 controller1.js 上的 use 方法上添加此参数。 我应该将这些参数发送到哪里?:

/***controller2.js***/
load('controller1'); // _controller siffix must be omitted
use('sharedFunction(params here?)', {params here?}) //where do I send the params?

非常感谢!

最佳答案

这是我所做的:

var sharedFunction = use('sharedFunction');

sharedFunction(param1, param2);

关于node.js - 如何在CompoundJS中通过 "use"方法传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16887216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com