Can you avoid repetition in such cases?

I try to avoid repetition in my code as much as possible. I know you can do this:

variable = variable+2


in that

variable += 2


but how can I avoid repetition here? Of course there is a way ...

this.className = this.className.replace("classname","")



source to share

3 answers

Unfortunately the answer is no, there are no abbreviations for this type of statement.



Make a function to do what you want? As for a = = I don't know how to overload operators in javascript ... see

Overloading arithmetic operators in JavaScript?



If you can use JQuery you can call





All Articles