简体   繁体   English

JavaScript有function个参数类型吗?

[英]Does JavaScript have function parameter types?

In PHP you can set function parameters (Or as there called in PHP arguements) to only accept a certain type(s) and a default value.在 PHP 中,您可以设置 function 参数(或在 PHP 参数中调用)以仅接受特定类型和默认值。 Is this possible in JavaScript?这在 JavaScript 中可能吗?

function test(bool $a = false) {
    
}

In the Atom code editor, when I type for example 'text'.substring() and I hover over the code, a tooltip window says this...在 Atom 代码编辑器中,当我键入例如 'text'.substring() 并在代码上输入 hover 时,工具提示 window 会这样说......

(Method) String.substring(start: number, end?: number)

The reason I want to be able to set the parameter types is to have this tooltip be accurate on my custom functions.我希望能够设置参数类型的原因是让此工具提示在我的自定义函数上准确无误。

Javascript variables don't have any types, but you can make a custom tooltip, possibly based off of comments inserted into the parameters of the functions, usin the Tooltip manager https://goodfoodgoodcode.com/2016/10/01/custom-tooltips-in-the-atom-text-editor/ Javascript 变量没有任何类型,但您可以使用工具提示管理器https://goodfoodgoodcode.com/2016/10/01/custom-制作自定义工具提示,可能基于插入到函数参数中的注释原子文本编辑器中的工具提示/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM