Clean Javascript Code

Callback as separate function

HTML

<div id="clickme">sdf</div>

CSS

#clickme {
    width: 100px;
    height: 100px;
    background-color: lightgreen;
}

JavaScript

Example = (function() {
    
  function Example() {
      this.registerListeners();
  }

  Example.prototype.registerListeners = function() {
    return $('#clickme').on('click', $.proxy(this.clicked, this));
  };

  Example.prototype.clicked = function() {
    return console.log('clicked');
  };

  return Example;
})();

new Example();