Closures
// ํด๋ก์ ๋ ๋ด๋ถํจ์(NestedFunction)์ด ์ธ๋ถํจ์์ ๋งฅ๋ฝ(Context)์ ์
๊ทผํ ์ ์๋ ๊ฒ์ ๊ฐ๋ฅดํจ๋ค - ์ํ์ฝ๋ฉ
function init() {
var name = "Mozilla";
function displayName() {
alert(name);
}
displayName();
}
init();
// Example of Closures in JavaScript- MOZILLA DEVELOPER
NETWORK
5.
Closures
// ํด๋ก์ ๋ ๋ด๋ถํจ์(NestedFunction)์ด ์ธ๋ถํจ์์ ๋งฅ๋ฝ(Context)์ ์
๊ทผํ ์ ์๋ ๊ฒ์ ๊ฐ๋ฅดํจ๋ค - ์ํ์ฝ๋ฉ
function makeFunc() {
var name = "Mozilla";
function displayName() {
alert(name);
}
return displayName;
}
var myFunc = makeFunc();
myFunc();
// Example of Closures in JavaScript- MOZILLA DEVELOPER
NETWORK
6.
Closures
// ํด๋ก์ ๋ ๋ด๋ถํจ์(NestedFunction)์ด ์ธ๋ถํจ์์ ๋งฅ๋ฝ(Context)์ ์
๊ทผํ ์ ์๋ ๊ฒ์ ๊ฐ๋ฅดํจ๋ค - ์ํ์ฝ๋ฉ
func makeFunc()->(()->String){
var name = "Swift"
func displayName() -> String {
return name
}
return displayName;
}
var myFunc = makeFunc();
myFunc();
// Example of Closures in JavaScript- MOZILLA DEVELOPER
NETWORK
// ํด๋ก์ ๋ ๋ด๋ถํจ์(Nested Function)์ด ์ธ๋ถํจ์์ ๋งฅ๋ฝ(Context)์ ์
๊ทผํ ์ ์๋ ๊ฒ์ ๊ฐ๋ฅดํจ๋ค - ์ํ์ฝ๋ฉ
Enumeration Syntax
enum StudyPerson{
case Kimin, GwangHo, Cody
}
var enumValue = StudyPerson.Kimin
enumValue = StudyPerson.GwangHo
enumValue = .Cody
24.
Enumeration Syntax
var enumValue= Study.Kimin
switch enumValue {
case Kimin:
// blah blah
case GwangHo:
// blah blah
case Cody:
// blah blah
}
25.
Enumeration Syntax
enum StudyPersonDetail{
case Name(String)
case Age(Int)
case EyeSight(Float,Float)
}
var codyName = StudyPersonDetail.Name("Cody")
var codyAge = StudyPersonDetail.Age(32)
var codyEyeSight = StudyPersonDetail.EyeSight(0.2,0.1)
switch codyEyeSight {
case .EyeSight(let left, let right):
left
right
case .EyeSight(let left, let right):
println("์ ์๋ ฅ์ (left):(right) ์ ๋๋ค.")
default:
"defulat case๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค."
}