저는 현재 자바 스크립트 상속에 대한 몇 가지 접근 방식을 시도하고 있습니다.자바 스크립트 상속
이 (http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm에서 '빌려') 내가 StreetGridView의 인스턴스를 만들 때
이제KV = {};
KV.extend = function(subClass, baseClass) {
function inheritance() {}
inheritance.prototype = baseClass.prototype;
subClass.prototype = new inheritance();
subClass.prototype.constructor = subClass;
subClass.baseConstructor = baseClass;
subClass.superClass = baseClass.prototype;
}
function GridView() {
var _ownerElement;
}
GridView.prototype.getOwnerElement = function() {
return this._ownerElement;
}
GridView.prototype.setOwnerElement = function(ownerElement) {
this._ownerElement = ownerElement;
}
GridView.prototype.initialize = function() {
this.setOwnerElement('test');
}
function StreetGridView(dataURL, ownerElement) {
StreetGridView.baseConstructor.call(this);
StreetGridView.superClass.initialize();
StreetGridView.superClass.setOwnerElement(ownerElement);
}
// subclass StreetGridView
KV.extend(StreetGridView, GridView);
, 나는 아무 문제 그것을() getOwnerElement를 호출 할 수 있습니다 : 나는 다음과 같은 코드가 있습니다. 모든 것이 예상대로 작동합니다.
그러나내가 다른 인스턴스를 만들
은 예 2에 대한 변경 사항은 난이 공유 인스턴스 정보로 프로토 타입을 사용하여 주요 문제 알고 다시1 인스턴스에 반영됩니다. 나는 오늘 아침에 내 머리를 짚어 봤지만 저를 올바른 방향으로 인도 할 수있는 누군가가 있는지 궁금해했습니다!
감사합니다.
여기 답변 : 여기 링크입니다 http://stackoverflow.com/a/12816953/885464 –