【问题标题】:How do I pass parameters through "use" method in CompoundJS?如何通过 CompoundJS 中的“use”方法传递参数?
【发布时间】:2013-06-02 20:53:06
【问题描述】:

我正在使用 CompoundJS(Express / NodeJS 的 MVC)。要在controller1.js 上的控制器the Doc says 之间共享代码,我可以使用publish 方法共享一个方法:

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

controller2.js 中,我可以通过loading 并尝试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 上的 usemethod 上添加此参数的方法或语法。 我将这些参数发送到哪里?

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

非常感谢!

【问题讨论】:

    标签: node.js controller express params compoundjs


    【解决方案1】:

    这是我所做的:

    var sharedFunction = use('sharedFunction');
    
    sharedFunction(param1, param2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-06
      • 2015-01-15
      • 1970-01-01
      • 2017-12-22
      • 2016-02-24
      • 2016-04-26
      • 1970-01-01
      相关资源
      最近更新 更多