è¿ä¸¤å¹´æ¥æç«ççææ¯æ 毫æ äºè®®çæ¯JavaScriptï¼éçES6çæ®åï¼ä¸ç®¡æ¯ä»å端çæµè§å¨æ¥çï¼è¿æ¯å端çNodeJSåºæ¯ï¼JavaScriptææ¯æ ä¸æçåä¸çè¯æèªå·±çä»·å¼ãJavaScript代ç è¶åè¶å¤§ï¼ä¼æå¨ç¥ï¼JavaScriptæ¯ä¸é¨å¨æè¯è¨ï¼ç¼ºå°éæç±»åæ£æ¥ï¼è¿æ ·å°±å¾é¾å¨ç¼è¯é¶æ®µæé¤æ´å¤çé®é¢ï¼å½ç¶ï¼è¿å°±æ¯å¨æè¯è¨çé
åæå¨ï¼è¿è¡æ¶å¨æå¤çç±»åï¼å¨æ们å代ç çæ¶åå°±å¯ä»¥å¾æ´çµæ´»ã为äºç»JavaScriptå¢å ç±»åæ£æ¥ä»¥åä¸äºå
¶ä»è½åTypeScriptåºè¿èçï¼ä¸è½è¯´TypeScriptæå¤çï¼åªè½è¯´TypeScript顺åºäºæ¶ä»£éè¦ãé£ä¹è¯´äºå天TypeScriptåJavaScriptåªç§è¯è¨æ´å
è¿å¢ï¼
让æ们ä»ä»¥ä¸æ¹é¢æ¥è°è°ï¼
1.ä»åå²å
袱è§åº¦è¯´JavaScriptçå
袱æ¯ååå
¼å®¹ï¼å³ä½¿èçæ¬çESä¸æè½åçæ¹é¢ï¼ä¸ºäºå
¼å®¹ï¼ä¹è¦æ¯æï¼èTypeScript宣称å®å
¨å
¼å®¹JavaScriptï¼è¿å¯¼è´äºTypeScript继æ¿äºJavaScriptä¸åç缺ç¹ï¼æ以ä»è¿ç¹ä¸çå¯ä»¥è¯´æ¯ä¸ç¸ä¼¯ä»²ã
2.TypeScriptçä½è
ä¹æ¯C#çä½è
ï¼è¿å¯¼è´äºTypeScriptä»C#继æ¿äºå¾å¤ä¼é
ç设计æ¯å¦æ举ï¼æ³åçè¯è¨ç¹æ§ï¼è¿è®©TypeScriptå¢è²ä¸å°ã
3.TypeScript带æç¼è¯æç±»åæ£æ¥ï¼å¨å大ç¨åºçæ¶åæä¼å¿ï¼æ´å®¹æéæå让å«äººç解代ç çæå¾ï¼ä½æ¯è¿å¸¦æ¥äºä¸ä¸ªé®é¢å°±æ¯è¯æ³ä¸çææ²åé¿ï¼ä¸å¤æ¼äº®ã
4.ç¥éGroovyåJavaçæåå容æçåºæ¥ï¼TypeScriptåJavaScriptçå
³ç³»å®é
ä¸å°±æ¯GroovyåJavaçå
³ç³»ï¼ä¸ä¸ªå¨æï¼ä¸ä¸ªéæï¼ä¸ä¸ªçµæ´»ï¼ä¸ä¸ªç¨³å¥ï¼åªä¸ªæ´å
è¿ï¼è¦çä½ ä»åªä¸ªæ¹é¢æ¥è¯´äºã
5. ä¸é¢æ¯å®æåæ ·åè½ç两段ç®å代ç ï¼å¤§å®¶å¯ä»¥ç®åæ¯è¾ä¸ä¸ï¼ççèªå·±å欢é£ç§åä½ã
TypeScript Code:
class Greeter {
greeting: string;
constructor (message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
JavaScript Code:
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
æ»ç»
TypeScript is c# version JavaScript, JavaScript is groovy version Java of Typescript which one is better depends on what you are going to do.
温馨提示:答案为网友推荐,仅供参考