Incomprehensible error message. Please help me understand why the following code

function Clock(options) { var elem = options.elem; var self = this; var flag, nowTime; //this.start(); self.nowTime = function() { this.nowTime = date(); }; elem.on('click', '#clock-start', this.start); this.start = function(){ console.log(44); } } var clock = new Clock({ elem: $('#clock') }); 

produces an error in the console

TypeError: this.start is not a function

in addition, if I place the body of the problem function directly in the handler as an unnamed function, then the code works without errors

  • @Sergey Kalinin; To format the code, select it with the mouse and click on the {} button of the editor. - Rules

1 answer 1

Declare start before elem.on('click', '#clock-start', this.start); .

  • thanks, it helped - cyklop77