Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// bad
- onclick="double_increment()"
- /// good
- const button = document.getElementById("some_id");
- button.addEventListener("click", double_increment);
- function Incrementer(name, value) {
- /// bad
- let mydiv = document.getElementById('mydiv');
- }
- class Incrementer {
- /// still bad though
- static target = "mydiv"
- }
- /// bad
- that.increment = function() {
- var i = parseInt(that.span.textContent) + 1;
- that.span.innerHTML = i;
- }
- /// better
- that.i = value;
- //increments value
- that.increment = function() {
- that.i++;
- }
- //updates UI
- that.update = function(){
- that.span.innerHTML = that.i;
- }
- // Method that should be called on button click
- that.handleOnClick = function(){
- that.increment();
- that.update();
- }
- /// bad
- function double_increment() {
- incrementer1.increment();
- incrementer2.increment();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement