Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

事件 #30

Open
xspider opened this issue Jun 3, 2013 · 0 comments
Open

事件 #30

xspider opened this issue Jun 3, 2013 · 0 comments
Labels

Comments

@xspider
Copy link
Collaborator

xspider commented Jun 3, 2013

<<返回目录

Events 是一个可以被mix到任意对象的模块,它拥有让对象绑定和触发自定义事件的能力。 事件在被绑定之前是不需要事先声明的,还可以携带参数。

看下面的例子:

var object = Chassis.mixin({}, Chassis.Events);

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

object.trigger("alert", "hi,Chassis!");

事件还提供了几种非常有用的API,详细的使用方法可以参考文档API。

在Chassis的里,事件无处不在,ModelView(PageView、SubView、GlobalView)、RouterHistory等都自动继承了Events的各种方法,比如,Model的属性被变更时会触发change事件,PageView切换时会触发onBeforePageIn/onAfterPageIn事件。

<<返回目录

@xspider xspider mentioned this issue Jun 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant