나는 자바 스크립트와 고민하고있다 고전 상속1. 최종 더글러스 크록 포드에, 자바 스크립트에서 클래식 모델을 지원하는 최초의 시도한다을 거부하는 동안, 나는 흥미 이해 찾습니다자바 스크립트 기생 상속
I have been writing JavaScript for 8 years now, and I have never once found need to use an uber function. The super idea is fairly important in the classical pattern, but it appears to be unnecessary in the prototypal and functional patterns. I now see my early attempts to support the classical model in JavaScript as a mistake.
그러나 기생 상속에 관한 어떤 정말 명확하지 뭔가가 :
function ZParenizor2(value) {
var that = new Parenizor(value);
that.toString = function() {
if (this.getValue()) {
return this.uber('toString');
}
return "-0-"
};
return that;
}
ZParenizor는 Parenizor의 관점에서 정의됩니다. 그러나 Parenizor는 기본 클래스이며 아무에게도 상속받지 않습니다. 따라서 this.uber
함수는 정의되지 않으며 새로운 ZParenizor2 객체의 toString
메서드를 호출하면 실제로 오류가 발생합니다.
맞나요? 아니면 무시하고 있습니까?
업데이트 내가 옳았 어. 이 메서드는 uber
메서드를 호출 할 필요가 없으므로 매개 변수로 0을 사용하여 ZParenizor를 만들 때만 작동합니다 (메서드 imeplementation에서 볼 수 있듯이).
Uncaught TypeError: Object #<error> has no method 'uber'
모든 개체는 적어도 Object.prototype에서 상속받습니다 ... –
글쎄, 오류는 무엇이라고 말합니까? –
예. 그 오류는 내가 생각한 것이 아니라 오타였다. 그러나 모든 객체가 객체 인 함수를 상속한다는 사실에 대해서는 생각하지 못했습니다. 감사! – user278064