var msg6 = "";
function A(){
var _localX = 7; // 내부 지역 변수
this._localX = 0; // 멤버 변수
this.getThisX = function() { return this._localX; };
this.getX = function() { return _localX; };
this.setX = function(x){ if(x<10){
_localX = x;
}
return _localX;
}
}
var obj6 = new A();
var x = obj6.getX();
msg6 += "\n x = " + x;
msg6 += "\n obj6._localX = " + obj6._localX;
msg6 += "\n obj6.getThisX = " + obj6.getThisX();
msg6 += "\n obj6.setX(8) = " + obj6.setX(8);
msg6 += "\n obj6.setX(18) = " + obj6.setX(18);
$('re').innerText = msg6;
/*
obj6._localX = 0
obj6.getThisX = 0
obj6.setX(8) = 8
obj6.setX(18) = 8
*/
'자바스크립트' 카테고리의 다른 글
객체리터럴 과 hasOwnProperty 함수의 프로퍼티나 메서드 있는지 확인 (0) | 2013.02.08 |
---|---|
객체의 인스턴스에 프로토타입 추가 (0) | 2013.02.08 |
클로저 로 함수 호출 방법 (0) | 2013.02.08 |
스코프체인 과 클로저 이해하기 (0) | 2013.02.08 |
(퀴즈)자바스크립트가 이렇게 어려울 줄이야 -.- (0) | 2013.02.08 |