Created
February 10, 2020 22:20
-
-
Save segdeha/d52375fe39f853fe5cf9865f12da58a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Counter(count, displaySelector, buttonSelector) { | |
this.count = count | |
this.displayElement = document.querySelector(displaySelector) | |
this.buttonElement = document.querySelector(buttonSelector) | |
this.setCount() | |
} | |
Counter.prototype = { | |
addEventListeners: () => { | |
this.buttonElement.addEventListener('click', this.increment) | |
}, | |
increment: () => { | |
this.count += 1 | |
}, | |
setCount: () => { | |
this.displayElement.innerHTML = this.count | |
} | |
} | |
// class Counter() { | |
// constructor() { | |
// } | |
// } | |
function init() { | |
let count = window.localStorage('count') || 0 | |
let counter = new Counter(count, '#count', 'button.count') | |
} | |
document.addEventListener('DOMContentLoaded' init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment