Is there a way in which I can make functions that are specific to the template and accessible by the template's event handlers? I don't want to pollute the global namespace.
I came upon this problem when I first noticed that I was repeating a lot of code between my event handlers in a manner similar to this:
Template.options.events({
"click .btn-1": function(e) {
// do something
var div;
div = $(e.target);
if (div.hasClass("active")) {
return div.removeClass("active");
} else {
return div.addClass("active");
}
},
"click .btn-2": function(e) {
// do something else
var div;
div = $(e.target);
if (div.hasClass("active")) {
return div.removeClass("active");
} else {
return div.addClass("active");
}
}
});
Note that I'm not trying to find a way to combine selectors, I already know how to do that. Notice that each button does something different, but have a few lines of repeated code. I want to keep this as DRY as possible without polluting the global namespace.