I turned to the source code of Backbone.js and found out that if your type of events
is a function, then the function is called, and the return value is used as an events
object.
This means that your code can be changed as follows:
app.views.Selfcare = Backbone.View.extend({ events: function() { var _events = { // all "standard" events can be here if you like } _events["events" + "with variables"] = "closeWindow"; return _events; }, closeWindow: function() { //code } });
THIS is an interesting part of the source code:
if (_.isFunction(events)) events = events.call(this);
Update:
An example is available in JSFiddle HERE **
source share