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.
you have typo in
prototype
.this.ev.on('click', this.userinput());
shouldthis.ev.on('click', this.userinput);
- want pass reference function it's executed when user clicks, don't want call when binding event handler.
Comments
Post a Comment