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

Events 不应该提供 mixTo 方法。 #14

Open
hotoo opened this issue Mar 2, 2014 · 2 comments
Open

Events 不应该提供 mixTo 方法。 #14

hotoo opened this issue Mar 2, 2014 · 2 comments

Comments

@hotoo
Copy link
Member

hotoo commented Mar 2, 2014

  1. mixTo 应该由第三方 mix 模块提供。
  2. Events.mixTo 方法不应该将 trigger 方法暴露。trigger 方法应该只提供给内部使用。
define("ModuleA", functioin(){
  var ModuleA = function(){};
  Events.mixTo(ModuleA);

  module.exports = ModuleA;
});

var a = new ModuleA();
// 触发事件是对象内部逻辑、状态,a 对象不应该拥有 `trigger` 方法。
@army8735
Copy link
Member

army8735 commented Mar 2, 2014

mix是为了让非Events派生的对象拥有事件功能。你的例子没看懂……
如果a对象不应该有events功能的话?那么在module内部var一个Events就好了,不暴露出来。
反倒是Events没有Class的extends等好奇怪,看代码想要继承Events的话,直接mix构造函数的。

@hotoo
Copy link
Member Author

hotoo commented Mar 2, 2014

我现在都是内部自己 var 并暴露 on 和 off 方法,从来没用过 mixTo 方法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants