A bindEvents does make sense but basically would be the same thing as .on().
What I suggest in your case is still binding to a selector instead of the actual button element:
- can.Control({
- defaults : {
- newButton : 'new-button'
- }
- }, {
- init: function() {
- this.element.after($("<button>Click Me</button>").addClass(this.options.newButton));
- }
- ".{newButton} click": function() {
- //do something
- }
- });
What you can also do is add the newButton element during setup() which allows you to avoid calling .on() again during init:
- can.Control({
- setup: function(el, options) {
- var newButton = $("<button>Click Me</button>");
- this.element.after(newButton);
- return can.Control.prototype.setup.cal(this, el, can.extend({
- newButton : newButton
- }, options));
- }
- "{newButton} click": function() {
- //do something
- }
- });