Javascript中的符号“:”是什么意思?
问题描述:
我发现这个代码在离子框架:Javascript中的符号“:”是什么意思?
import { AlertController } from 'ionic-angular';
export class MyPage {
constructor(public alertCtrl: AlertController) {
}
又有什么:
在alertCtrl: AlertController
手段?
答
的:在打字稿意味着类型分配/注释......
alertCtrl: AlertController
手段声明alertCtrl
为AlertController
,这将只接受AlertController
型Objects
。
count:number
表示将计数声明为数字,只接受number
。
name:string
表示声明为字符串的名称,该字符串只接受string
。
答
代码是用TypeScript编写的,它是一种编译为JavaScript的语言。 :
符号用于指定键入。它可以在变量声明之后指定其类型,在函数的参数之后或函数的标题之后指定它的返回类型(可以是void)。
例子:
let a: number = 8;
function (b: number): number { return b; }
这会是打字稿? – JanR
[这个符号在JavaScript中的含义是什么?](http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript)可能有一个重复的问题,具体的符号:http://stackoverflow.com/questions/39655737/javascript-strange-syntax-that-works-but-how –
可能的重复http://stackoverflow.com/questions/418799/what-does-colon- do-in-javascript –