에 private 멤버에 액세스하는 데, 나는더 나은 방법은 자바 스크립트의 <a href="http://javascript.crockford.com/prototypal.html" rel="noreferrer">prototypical inheritance model</a>에 비트를 읽은 후 자바 스크립트
var Some_Class = function() {
(function() {
// constructor
}).call(this)
}
Some_Class.prototype.public_method = function() {
};
에
var Some_Class = function() {
this.public_method = function() {
};
(function() {
// constructor
}).call(this)
}
에서 클래스를 구성하는 내 스타일을 변경 좋은 방법이지만 더 이상 공용 메서드에서 개인 메서드에 액세스 할 수 없습니다.
var Some_Class = function() {
var private_member = 'whatever';
(function() {
// constructor
}).call(this)
}
Some_Class.prototype.public_method = function() {
return private_member; // not possible
};
기사 here (폐쇄 만든 생성자)를 통해 읽은 후, 나는이 일의 단점은 무엇인가, 그러나이
var Some_Class = function() {
var private_member = 'whatever',
private_method = function(_some_value) {
// private method implementation
};
if(!arguments.callee.prototype.public_method) {
arguments.callee.prototype.public_method = function() {
private_method.call(this, private_method);
};
}
(function() {
// constructor
}).call(this)
}
나왔다! 또는 public 메서드에서 private member에 액세스하려는 경우이 작업을 수행하는 더 좋은 방법이 있습니까?
덕분에 ... 난 여전히 개체 모델에 매우 익숙하지 오전 PHP/자바/기타 OOP의 OOP 코드와 유사한 내 코드를 만들기 위해 원하는 때문에 아마 추측 프로그래밍 언어 – Jeffrey04