Skip to content

Instantly share code, notes, and snippets.

@webpapaya
Created November 11, 2020 16:30
Show Gist options
  • Save webpapaya/15ba7eb3d55964512b360055184ca785 to your computer and use it in GitHub Desktop.
Save webpapaya/15ba7eb3d55964512b360055184ca785 to your computer and use it in GitHub Desktop.
code from lecture Frontend Development (2020-11-05)
function calculator() {
let value = 0
return function (difference) {
value += difference
console.log(value)
}
}
const calulator1 = calculator()
calulator1(10) // 10
calulator1(-1) // 9
function newCounter(name) {
for(let i = 0; i < 10; i++) {
}
let i = 0;
return function () {
i++;
console.log(name + '; ' + i);
}
}
const counter1 = newCounter('test')
counter1() // test; 1
counter1() // test; 2
class Counter {
constructor(name) {
this.name = name
this.i = 0
}
increment() {
this.i++;
console.log(name + '; ' + this.i);
}
}
const counter2 = new Counter('test')
counter2.increment() // test; 1
(function () {
var someVariable = 'irrelevant'
console.log(someVariable);
}());
function main () {
var someVariable = 'irrelevant'
console.log(someVariable);
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment