EASELJS 라이브러리에서 개체를 상속하고 있습니다. 문제를 단순화하기 위해 코드를 최소 형식으로 축소했습니다.자바 스크립트 개체 멤버 변수가 복제되지 않습니다.
이this.TESTProg = this.TESTProg || {};
(function() {
var _jsbutton = function(x, y, text, icon) {
p.init(x, y, text, icon);
};
var p = _jsbutton.prototype = new createjs.Container();
p.x = 0;
p.y = 0;
p.text = null;
p.icon = null;
p.init = function(x, y, text, icon) {
this.x = 0 + x;
this.y = 0 + y;
this.text = "" + text;
this.icon = null;
};
TESTProg._jsbutton = _jsbutton;
})();
그럼 내가 다른 JS 객체에서 사용 :
var buttoncancel = new SJSGame._jsbutton(
profileselConfig.cancelx, //this is defined in another jsfile:
profileselConfig.cancely,
"cancel", "_cancel.png");
console.log(buttoncancel.y); //this gives 240
var buttoncancel2 = new SJSGame._jsbutton(
profileselConfig.cancelx,
profileselConfig.cancely - 40,
"cancel", "_cancel.png");
console.log(buttoncancel.y); //this gives 200
console.log(buttoncancel2.y); //this gives 200
buttoncancel2.y = 100;
console.log(buttoncancel.y); //this now gives 200 (not changed by the second object)
console.log(buttoncancel2.y); //this now gives 100
설정 파일이 :
var _profileselConfig = function(){
this.cancelx = 0;
this.cancely = 240;
};
profileselConfig = new _profileselConfig();
그리고 내가 무슨 잘못을하고있는 중이 야
는 전 클래스가?참조를 전달하지 않으려면 이미 0을 사용하고있어 작동하지 않습니다. 지금 어떻게해야합니까? 어떤 제안? 감사.
[EaselJS : 누군가가 데모에 사용 된 상속 패턴을 설명 할 수 있습니까?] (http://stackoverflow.com/questions/18008421/easeljs-can-somebody-explain-the-inheritance-pattern-used-in -demos) – Bergi