In my js code I noticed many statements like:
model.set({someAttribute : !model.get("someAttribute")});
So I thought it may be useful to define custom method in the model:
toggle: function(attr, silent){
this.set({attr: !this.get(attr)}, silent? {silent:true} : {});
}
The problem is, javascript javascript treats ‘attr’ as an actual key name instead of formal function parameter, so the code above doesn’t work. Any suggestions how to solve this problem?
I want an elegant one-line solution.
there isn’t an elegant one-line solution for this. in order to use
attras the key, you have to declare the object literal and then set it using the[]syntax: