Created
November 11, 2020 16:30
-
-
Save webpapaya/15ba7eb3d55964512b360055184ca785 to your computer and use it in GitHub Desktop.
code from lecture Frontend Development (2020-11-05)
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 calculator() { | |
let value = 0 | |
return function (difference) { | |
value += difference | |
console.log(value) | |
} | |
} | |
const calulator1 = calculator() | |
calulator1(10) // 10 | |
calulator1(-1) // 9 |
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 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 |
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 () { | |
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