- Expert Angular
- Mathieu Nayrolles Rajesh Gunasundaram Sridhar Rao
- 135字
- 2021-07-15 17:05:33
Functions
JavaScript, which follows the ES5 specs, does not support classes and modules. However, we tried to scope variables and modularity using functional programming in JavaScript. Functions are the building blocks of an application in JavaScript.
Though TypeScript supports classes and modules, functions play a key role in defining a specific logic. We can define both named functions and anonymous functions in JavaScript as follows:
//Named function function multiply(a, b) { return a * b; } //Anonymous function var result = function(a, b) { return a * b; };
In TypeScript, we define functions with the type of the parameters and the return type using function arrow notation, which is also supported in ES6, as follows:
var multiply:(a: number, b: number) => number = function(a: number, b: number): number { return a * b; };
推薦閱讀
- C#編程入門指南(上下冊)
- 差分進(jìn)化算法及其高維多目標(biāo)優(yōu)化應(yīng)用
- Python數(shù)據(jù)挖掘與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- 算法訓(xùn)練營:提高篇(全彩版)
- 從0到1:Python數(shù)據(jù)分析
- SQL Server從入門到精通(第3版)
- Windows內(nèi)核編程
- 領(lǐng)域驅(qū)動設(shè)計:軟件核心復(fù)雜性應(yīng)對之道(修訂版)
- 執(zhí)劍而舞:用代碼創(chuàng)作藝術(shù)
- Mastering Akka
- JavaScript腳本特效編程給力起飛
- 交互式程序設(shè)計(第2版)
- Oracle 12c從入門到精通(視頻教學(xué)超值版)
- Learning C++ by Creating Games with UE4
- 精通Spring:Java Web開發(fā)與Spring Boot高級功能