Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. /// bad
  2. onclick="double_increment()"
  3.  
  4. /// good
  5. const button = document.getElementById("some_id");
  6. button.addEventListener("click", double_increment);
  7.  
  8. function Incrementer(name, value) {
  9. /// bad
  10. let mydiv = document.getElementById('mydiv');
  11. }
  12.  
  13. class Incrementer {
  14. /// still bad though
  15. static target = "mydiv"
  16. }
  17.  
  18. /// bad
  19. that.increment = function() {
  20. var i = parseInt(that.span.textContent) + 1;
  21. that.span.innerHTML = i;
  22. }
  23.  
  24. /// better
  25. that.i = value;
  26.  
  27. //increments value
  28. that.increment = function() {
  29. that.i++;
  30. }
  31.  
  32. //updates UI
  33. that.update = function(){
  34. that.span.innerHTML = that.i;
  35. }
  36.  
  37. // Method that should be called on button click
  38. that.handleOnClick = function(){
  39. that.increment();
  40. that.update();
  41. }
  42.  
  43. /// bad
  44. function double_increment() {
  45. incrementer1.increment();
  46. incrementer2.increment();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement