我正在认真考虑从PHP切换到Node.js。但我不太喜欢Javascript中的原型,所以我会优先考虑Typescript。Node.js Typescript包含
我只是测试基本知识,并创建了一个新的(打字稿)快递在Visual Studio 2013年我已经安装了Node.js for Visual Studio项目。
我创建了一个称为tstests目录,添加的文件从打字稿教程下面的代码称为animals.ts:
class Animal {
name: string;
constructor(theName: string) { this.name = theName; }
move(meters: number) {
alert(this.name + " moved " + meters + "m.");
}
}
class Snake extends Animal {
constructor(name: string) { super(name); }
move() {
alert("Slithering...");
super.move(5);
}
}
class Horse extends Animal {
constructor(name: string) { super(name); }
move() {
alert("Galloping...");
super.move(45);
}
}
然后添加以下一段代码app.ts:
/// <reference path='tstests/animals.ts'/>
var sam = new Snake("Sammy the Python");
sam.move();
两个智能感知,建设项目工作,但是当我尝试运行项目,我得到的ReferenceError:未定义蛇。
任何人都可以向我解释我如何解决这个问题?
这解释了它多一点:https://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1 – basarat