2
내가 이런 foo.ts
생성 :Nodejs REPL에서 Typescript 클래스를 사용하는 방법?
class Foo{
public echo(){
console.log("foo");
}
}
를 그리고이 같은 자바 스크립트 코드를 출력합니다
var Foo = (function() {
function Foo() {
}
Foo.prototype.echo = function() {
console.log("foo");
};
return Foo;
})();
내가 nodejs REPL에서
echo
함수를 호출 할,하지만이 같은 오류를 끝
:
$ node
> require('./foo.js');
{}
> f = new Foo
ReferenceError: Foo is not defined
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
at emitKey (readline.js:1095:12)
어떻게 클래스를 인스턴스화하고 함수 echo
을 호출 할 수 있습니까?
typescript의 작동 방식을 잘 모르겠지만 Foo.js에서 아무 것도 내보내지 않았 음이 분명합니다. 또한 requi를 할당하지 않았습니다. 적색 모듈). 어쩌면 노드의 모듈 시스템을 먼저 익숙하게 만들 수 있습니다. –