나는 내 자신의 프로그래밍 스타일에 맞는 node.js에서 프로토 타입 상속을 수행하는 방법을 찾고 있습니다. 가장 중요한 것은 전역 네임 스페이스를 "오염시키는"대신에 변수를 사용하는 것입니다 (그 생각이 마음에 들지 않는다면이 이름을 건너 뛰십시오). 주제 (Google에 270000 개가 넘는 항목)에 대한 설명이 적어도 6 건 이상 발견되었습니다.node.js의 프로토 타입 상속
var B = function() {
this.value = 2;
print();
}
:이 내가 같은 더 복잡한 물건을 할 수 있기를 바랍니다 어떻게 작동하는지 알게되면
> var A = function() {
... this.value = 1;
... };
> A.prototype.print = function() {
... console.log(this.value);
... }
[Function]
> var a = new A();
> a.print();
1
> var B = function() {
... this.value = 2;
... };
> B.prototype.__proto__ = A.prototype;
> b = B();
> b.print()
TypeError: Cannot call method 'print' of undefined
at [object Context]:1:3
at Interface.<anonymous> (repl.js:150:22)
at Interface.emit (events.js:42:17)
at Interface._onLine (readline.js:132:10)
at Interface._line (readline.js:387:8)
at Interface._ttyWrite (readline.js:564:14)
at ReadStream.<anonymous> (readline.js:52:12)
at ReadStream.emit (events.js:59:20)
at ReadStream._emitKey (tty_posix.js:286:10)
at ReadStream.onData (tty_posix.js:49:12)
: 여기
내가 가장 유망한 변종을 발견하지만 난 뭔가 잘못을 가지고 무엇을
위대한! 많은 감사, 당신은 내 하루를 구했습니다. – mark