最近我和一些同事讨论了一些我发现不正确的东西。 我们使用了大量的应用骨干网和我的方式来创建视图是 “标准”骨干路:将函数传递给Backbone.View.extend
var MyView = Backbone.View.extend({
className: 'foo',
initialize: function() {
_.bindAll(this, 'render' /* ... more stuff */);
},
render: function() {
/* ... render, usually
using _.template and passing
in this.model.toJSON()... */
return this;
}
});
但有人在团队最近决定做这样说:
var MyView = Backbone.View.extend((function() {
/* 'private stuff' */
function bindMethods(view) {
_.bindAll(view, /* ... more stuff */);
};
function render(view) {
/* ... render, usually
using _.template and passing
in view.model.toJSON()... */
};
return {
className: 'foo',
initialize: function() {
bindMethods(this);
render(this);
}
};
}());
这就是伪代码的想法。 读了BB源和阅读教程,文章我觉得这是一个 不好的做法(对我来说是没有意义的),但我从 其他骨干开发者/用户喜欢一些反馈提前
谢谢
就我个人而言,我不认为需要像这样封闭视图,这会降低可读性。 – c4urself 2011-12-14 09:06:44
非常同意。这是不可读的......但比我认为这可能导致混乱。感谢您的反馈 – 2011-12-14 09:09:25