- 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; };
推薦閱讀
- Flask Blueprints
- OpenShift開發(fā)指南(原書第2版)
- Java系統(tǒng)分析與架構(gòu)設計
- JavaFX Essentials
- Learning Elixir
- Django:Web Development with Python
- Data Analysis with IBM SPSS Statistics
- 云計算通俗講義(第3版)
- Magento 1.8 Development Cookbook
- SQL Server 2012數(shù)據(jù)庫管理與開發(fā)項目教程
- Multithreading in C# 5.0 Cookbook
- Machine Learning in Java
- 后臺開發(fā):核心技術與應用實踐
- 分布式數(shù)據(jù)庫原理、架構(gòu)與實踐
- Magento 2 Developer's Guide