在javascript中函数声明后冒号 [英] Colon after function declaration in javascript
问题描述
我正在浏览Vue.js的源代码。在几乎所有的函数声明中,我找到了一种定义函数的新方法
I am going through source code of Vue.js. In almost all the function declarations I find a new way of defining functions
function isStringStart (chr: number): boolean {
return chr === 0x22 || chr === 0x27
}
有人可以解释一下这种函数声明是什么叫做?
Can somebody explain me what is this kind of function declaration called?
推荐答案
这是一个类型声明。 :boolean
基本上是指<code> isStringStart 函数必须返回 boolean
价值。与参数的类型声明相同。 chr:number
表示该函数接受一个参数,该参数必须是typeof number。
That's a type declaration. :boolean
means basically, that the isStringStart
function must return a boolean
value. The same with the argument's type declaration. chr: number
means, that the function accepts one argument, which has to be typeof number.
如果未满足要求(未传递正确的参数或返回错误的值),您使用的类型检查库将引发错误。
If the requirements are not fulfilled (not proper arguments are passed or wrong value is being returned), the typechecking library you are using will throw an error.
这篇关于在javascript中函数声明后冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!