Answer the question
In order to leave comments, you need to log in
Am I using jquery and oop correctly?
Instead of this
$('.test').click( function() {
$(this).remove();
});
class Test {
constructor(item) {
this.wrapper = $(item);
this.setClickEvent();
}
setClickEvent(item) {
this.wrapper.click( () => {
// do some things
this.remove();
});
}
remove() {
// do some things
this.wrapper.remove();
}
}
new Test('.test');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question