Last active
May 29, 2017 04:14
-
-
Save SeonghuiChoe/92b2745348cb60907dc4f3e489c60724 to your computer and use it in GitHub Desktop.
javascript 문제 두번째
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
var privacy = { | |
secret: "I did not study last night.", | |
getSecret: function () { | |
return this.secret; | |
} | |
}; | |
var what = privacy.getSecret; | |
console.log(what()); |
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
var c; | |
document.write(typeof typeof c); |
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
function setter(aryUnits) { | |
for (var i = 0; i < aryUnits.length; i++) { | |
var id = i + 1; | |
aryUnits[i] = new Object(); | |
aryUnits[i].getId = function () { | |
return id; | |
} | |
} | |
} | |
var ary = new Array(5); | |
setter(ary); | |
document.write(ary[3].getId()); |
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. 키워드 this에 대해 묻는 문제입니다. | |
what 변수에 함수를 할당하여, 전역 컨텍스트에서 함수를 실행했으므로 해당 함수내의 this는 글로벌 객체가 되고, | |
글로벌 객체에는 secret이라는 프로퍼티가 없으므로 undefined 가 됩니다 | |
2. 자바스크립트의 해석순서와 typeof의 반환값에 대해 묻는 문제입니다. | |
typeof는 왼쪽에서 순서대로 연산을 처리하여 선언만 된 변수 c의 타입을 반환하는데 이 경우 문자열 "undefined"가 되며, | |
이것을 다시 typeof하면 "string"입니다. | |
3. 자바스크립트의 객체가 참조 타입이라는 것과 클로저의 스코프에 대해 묻는 문제입니다 | |
빈 5만큼의 길이를 갖는 배열을 선언한 뒤 함수에 인자로 주고 있습니다. | |
참조 타입으로 전달되므로 함수에서 배열에 어떠한 조작을하면 리턴값이 없어도 인자의 배열은 내용물이 변합니다. | |
함수 안에서는 getId라는 함수를 가진 객체를 할당하고 있지만, 클로저의 스코프상 모든 배열객체들은 같은 메모리상의 id를 참조할 겁니다. | |
for 문이 종료되며 id 변수는 5가 할당되고, 배열의 모든 객체의 getId는 5를 반환합니다. |
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
다음 알파벳 중, 여섯 글자를 지워서 한 단어를 만들어라. | |
SBIANXLEATNTEARS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment