如何将数据从一个模块发送到另一个模块?

时间:2022-06-04 07:10:43

i want to send data from one of my modules to another module, which handles the data.

我想将数据从我的一个模块发送到另一个处理数据的模块。

I got three modules: Requester, Controller, Displayer

我有三个模块:请求者,控制器,显示器

Controller: Inits Requester and Displayer

控制器:Inits Requester和Displayer

Requester: Makes a server request and gets response data stored in an variable responseData

请求者:发出服务器请求并获取存储在变量responseData中的响应数据

Now i want to send this variable to the Controller and from there it should be passed to the Displayer

现在我想将此变量发送到Controller,然后将其传递给显示器

I don't know how i should implement this, because I'm new to JavaScript and those Design Patterns.

我不知道我应该如何实现它,因为我是JavaScript和那些设计模式的新手。

For this context I'm using the Revealing Module Pattern...

对于这种情况,我正在使用Revealing Module Pattern ...

App.Displayer = (function() {...})();
App.Controller = (function() {...})();
App.Requester = (function() {...})();

1 个解决方案

#1


0  

The revealing module pattern is used to keep functions private inside of each module. Functions inside the (function(){//here})() pattern cannot be accessed outside of module. To answer your question, when you want to reveal the data, you simply return the object (function(){return{key: value}})()and you can access it like module.key = value. To pass this public object, you can pass it in as an argument to the module.

揭示模块模式用于将功能保持在每个模块内部。无法在模块外部访问(function(){// here})()模式内的函数。要回答您的问题,当您想要显示数据时,只需返回对象(function(){return {key:value}})(),您就可以像module.key = value一样访问它。要传递此公共对象,可以将其作为参数传递给模块。

#1


0  

The revealing module pattern is used to keep functions private inside of each module. Functions inside the (function(){//here})() pattern cannot be accessed outside of module. To answer your question, when you want to reveal the data, you simply return the object (function(){return{key: value}})()and you can access it like module.key = value. To pass this public object, you can pass it in as an argument to the module.

揭示模块模式用于将功能保持在每个模块内部。无法在模块外部访问(function(){// here})()模式内的函数。要回答您的问题,当您想要显示数据时,只需返回对象(function(){return {key:value}})(),您就可以像module.key = value一样访问它。要传递此公共对象,可以将其作为参数传递给模块。