简体   繁体   English

有人可以解释骨干调度员的工作吗?

[英]Can someone explain what the Backbone dispatcher does?

So I'm learning Backbone from scratch using the documentation. 因此,我正在使用文档从头开始学习Backbone。

Here is the snippet im trying to understand 这是我试图理解的片段

var object = {};

_.extend(object, Backbone.Events);

object.on("alert", function(msg) {
  alert("Triggered " + msg);
});

object.trigger("alert", "an event");

For example, to make a handy event dispatcher that can coordinate events among different areas of your application: var dispatcher = _.clone(Backbone.Events) 例如,要创建一个方便的事件分发程序,它可以在应用程序的不同区域之间协调事件:var dispatcher = _.clone(Backbone.Events)

The code above works like a charm but I don't get the dispatcher part, what does it do? 上面的代码就像一个咒语,但是我没有得到调度程序部分,它有什么作用? And how do I use it, already googled but the examples were too advanced for me =/ 以及如何使用它,已经用谷歌搜索,但是示例对我来说太高级了= /

This is one of several possible ways to decouple views. 这是解耦视图的几种可能方式之一。 Decouple mean is to make one view know nothing about another one. 解耦的意思是使一个视图对另一视图一无所知。 Decoupling makes parts of your application independent of each other. 解耦使应用程序的各个部分彼此独立。 This is good for debugging, reusability and so on. 这对于调试,可重用性等很有用。

Example you provided is not complete and it seems the reason why you don't understand what does it do and what is the purpose. 您提供的示例还不完整,这似乎是您不了解它的作用和目的的原因。

Good detailed article for this issue: http://blog.safaribooksonline.com/2013/10/02/decoupling-backbone-applications-with-pubsub/ 有关此问题的很好的详细文章: http : //blog.safaribooksonline.com/2013/10/02/decoupling-backbone-applications-with-pubsub/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM