Created
September 18, 2020 14:46
-
-
Save splex7/0019e85e6bd9ffe2e75682fbc39eda10 to your computer and use it in GitHub Desktop.
This file contains 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
// [1] 클로저 | |
function foo() { | |
let yabal = []; | |
return { | |
addYabal(x) { yabal = [x, ...yabal] }, | |
getYabal() { return yabal } | |
}; | |
} | |
const bar = new foo(); | |
bar.addYabal('rom'); | |
// [2] - X async function이 synthetic sugar 라서 function이 아니라 Promise기 때문에 new 가 안먹음 | |
function foo() { | |
return (async ()=> { | |
let yabal = []; | |
let config = await (await fetch('...')).json(); | |
return { | |
addYabal(x) { yabal = [x, ...yabal] }, | |
getYabal() { return yabal }, | |
}; | |
})(); | |
} | |
const bar = new foo(); | |
bar.addYabal('rom'); | |
// [3] - O 즉시실행함수로 감싸주자 | |
function foo() { | |
return (async ()=> { | |
let yabal = []; | |
let config = await (await fetch('...')).json(); | |
return { | |
addYabal(x) { yabal = [x, ...yabal] }, | |
getYabal() { return yabal }, | |
}; | |
})(); | |
} | |
const bar = new foo(); | |
bar.addYabal('rom'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment