Skip to content

Instantly share code, notes, and snippets.

@segdeha
Created February 10, 2020 22:20
Show Gist options
  • Save segdeha/d52375fe39f853fe5cf9865f12da58a6 to your computer and use it in GitHub Desktop.
Save segdeha/d52375fe39f853fe5cf9865f12da58a6 to your computer and use it in GitHub Desktop.
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