그대는 지금 실수하고 있다. 쟈스의 방식은 따로있다... 이것은 하나의 슈가..
var Klass = function(Parent, props) {
var Child, F, i;
Child = function() {
if (Child.uber && Child.uber.hasOwnProperty("__construct")) {
Child.uber.__construct.apply(this, arguments);
}
if (Child.prototype.hasOwnProperty("__construct")) {
Child.prototype.__construct.apply(this, arguments);
}
};
Parent = Parent || Object;
F = function () {};
F.prototype = Parent.prototype;
Child.prototype = new F ();
Child.uber = Parent.prototype;
Child.prototype.constructor = Child;
for (i in props) {
if (props.hasOwnProperty(i)) {
Child.prototype[i] = propsp[i];
}
}
return Child;
}
var Man = Klass(null, {
__construct: function (what) {
console.log("Man's constructor");
this.name = what;
},
getName: function() {
return this.name;
}
});
var SuperMan = Klass(Man, {
__construct: function (what) {
console.log("SuperMan's constructor");
this.name = what;
},
getName: function() {
var name = SuperMan.uber.getName.call(this);
return "I am " + name;
}
});
나는 이 코드가 더 장점이안보이는데...
3중 상속안됨? uber.uber 로 참조거슬러가야함?
아니뭣보다 construct 는 왜 무조건 실행하는건데..
무한상속 가능하다. 깨달아라!
아둔한 자여
무한 상속가능한건 암
SuperMan.uber.getName.call(this); 직관적이지 못함
__construct 무조건 호출하는것은 좀 아니라고생각함
아둔한 길을 고집하는군..
__construct는 private멤버를 override 할때만 하면되는거시고..
그밖에 퍼블릭 메서드도 override 할때만 해주면되는거시다...
자스가 아둔한 언어라 그래
하나를 알려줘도 하나를 온전히 취하지 못하는구나!
아둔해서 무슨말인지 이해가안가니 소스로 설명좀요;
Child.prototype = new F (); 해서 서브의 프로토타입을 빈객체로 만들고 prop를 추가함으로써 부모의 prototype을 안전하게 만들고 우버.콘스터럭으로 프라이비한 부모의 prototye을 오버라이딩한다는거같은데 이게시발 내가 한 질문이랑 무슨상관인거야