Ich bin neu in OOP in jQuery.OOP: jQuery Klassenmethode Aufruf auf Klick-Ereignis
Ich habe folgende Klasse
/*
* myClass
*/
var AlcoholOrder = function (options) {
/*
* Variables accessible
* in the class
*/
var vars = {
myVar: 'original Value'
};
/*
* Can access this.method
* inside other methods using
* root.method()
*/
var root = this;
/*
* Constructor
*/
this.construct = function (options) {
$.extend(vars, options);
};
var addRemoveFavorite = function(){
alert('function called');
};
$(function() {
$(document.body).on('click', '.favorite-add', this.addRemoveFavorite);
});
/*
* Pass options when class instantiated
*/
this.construct(options);
};
Jetzt habe ich mit folgendem Code meine Klasse auf einer Seite bin initialisiert.
Ich möchte addRemoveFavorite
Methode aufrufen, wenn Klick Ereignis ausgelöst. Derzeit, wenn ich klicke, bekomme ich Fehler
jquery-1.12.4.min.js:3 Uncaught TypeError: ((n.event.special[g.origType] || {}).handle || g.handler).apply is not a function
Ich weiß nicht, wie Klassenmethode auf Click-Ereignis aufrufen. Ich habe gesucht, aber keine richtige Lösung bekommen.
Oh ja. das war mein Fehler. Danke @llama, um mich zu führen. – Dhara
Gern geschehen. – llama