Answer the question
In order to leave comments, you need to log in
OOP + jQuery, how to do it right?
Tell me, I created a class in JS that will work with discounts (load the number of bonus points via AJAX, then calculate how much it is in money, and process the input where managers will enter the amount to write off bonuses).
It looks like this: pastebin.com/BqqwtPZK
I use the methods of this class as event handlers, the problem is that I pass my own this
, and I have to declare some var self = affiliate
.
I seem to be confused with this and prototypal OOP, I get the feeling that I'm doing something wrong. How do I change object properties correctly in conjunction with jQuery event handlers?
PS Do not offer all sorts of Vue and Angular, according to the TK, it is jQuery.
Answer the question
In order to leave comments, you need to log in
The this keyword in javascript works differently than in other languages.javascript.ru/tutorial/object/thiskeyword
Unlike PHP, Java, C++, etc., the this value in JavaScript is not statically bound to any object, but depends on the context of the call.
var self = affiliate
id: self.customerId
You could just writeid: affiliate.customerId
I got the feeling that I was doing something wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question