0
http://jsfiddle.net/raylu/C6Tkn/이 JS 스 니펫에서 컨텍스트가 변경되는 이유는 무엇입니까?
function a() {
document.write(this + '<br />');
}
a();
a.apply('hello');
var b = function() {
a();
}
b.apply('hi');
내가 출력 마지막 줄을 기대할 수있는 '안녕하세요', 대신에이 창을 출력합니다.
[MDN에는'this'에 관한 좋은 페이지가 있습니다.] (https://developer.mozilla.org/en/JavaScript/Reference/Operators/this). 'func();'와 같은 함수를 호출 할 때마다,'this'는 전역 객체를 참조 할 것입니다. –
[함수 인수를 문자열 또는 참조로 전달할 때 'this'가 변경되는 이유는 무엇입니까?] (http://stackoverflow.com/questions/5883619/why-does-this-change-when-passing-the-function -argument-as-string-or-reference) – PeeHaa