-
Notifications
You must be signed in to change notification settings - Fork 34
Closed
Milestone
Description
可能很多人都不知道这个功能,我也是最近看代码才发现的
var Test = Base.extend({
attrs: {
onFocus: spy1,
onChangeXx: spy2,
beforeShow: spy3
},
show: function() {}
});
看看这个功能是如何用的,可以将一个属性注册为事件,如
onFocus 会将函数注册到 'focus' 事件上,onChangeXx 会将函数注册到 'change:xx' 事件上。beforeShow 则是将函数注册到 'before:show' 事件上。
先从分类上说,before/after 是对方法做切面,change 监听属性的变化,on 是最普通的监听。这些都放到 attr 上会很混乱,容易造成误解。
从用户角度说,这些都可以用实例方法去实现,更加优雅,如
var t = new Test();
t.on('focus', function() {});
t.before('show', function() {});
t.on('change:xx', function() {});
所以我觉得这个功能可以去掉。
Metadata
Metadata
Assignees
Labels
No labels