javascript - js code shows error after creating new instance of object -


when create new instance of clickevent object returns following error. click here jsfiddle code. below code

var clickevent = function (event) {     this.ev = $('.' + event);     this.ev.on('click', this.userinput()); };  clickevent.protoype = function () {     return {         userinput: function () {             console.log('user');         },          show: function () {             console.log('show');         }     };    }();  var c = new clickevent('event');     c.show(); 

why show error , how can solve it?

uncaught typeerror: object [object object] has no method 'userinput'  

there couple of issues.

  1. you have typo in prototype.

  2. this.ev.on('click', this.userinput()); should this.ev.on('click', this.userinput); - want pass reference function it's executed when user clicks, don't want call when binding event handler.


Comments