我正在构建一个 Backbone Marionette 应用程序。在 Marionette 中,您可以执行以下操作:
Marionette.Application.extend({
regions: {
mainRegion: function(){return someCondition?"#A":"#B"},
otherRegion: "#something"
}
})
我正在尝试使用自定义对象在我的应用程序中实现此功能。实现这一目标的最佳方法是什么? 目前,我正在检查每个值:
if(typeof obj == "function") {
this.data.obj = obj();
}
else {
this.data.obj = obj;
}
或相应的 ?: 表达式。 有没有更简单的方法来做到这一点?
最佳答案
Underscore 有一个 result
方法,可以完全满足您的需求(请参阅 http://underscorejs.org/#result )
您可以在这里找到实现:http://underscorejs.org/docs/underscore.html#section-128
关于Javascript 通过返回字符串的函数动态对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21489000/