paint-brush
Swift and JavaScript comparison snippets(8) — Classesby@unbug

Swift and JavaScript comparison snippets(8) — Classes

by unbugJuly 3rd, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Swift
featured image - Swift and JavaScript comparison snippets(8) — Classes
unbug HackerNoon profile picture

Swift













// class definitionclass Counter {var count = 0func increment() {count += 1}func increment(by amount: Int) {count += amount}func reset() {count = 0}}









// class instancelet counter = Counter()// the initial count value is 0counter.increment()// the count's value is now 1counter.increment(by: 5)// the count's value is now 6counter.reset()// the count's value is now 0

print("The count property value is \(counter.count)")

JavaScript















// class definitionclass Counter {contructor() {this.count = 0}function increment() {this.count += 1}function increment(amount) {this.count += amount}function reset() {this.count = 0}}









// class instancelet counter = Counter()// the initial count value is 0counter.increment()// the count's value is now 1counter.increment(5)// the count's value is now 6counter.reset()// the count's value is now 0

console.log(`The count property value is ${counter.count}`)

More of Swift and JavaScript comparison snippets