请问 vscode 中 js 中将对象传递给函数的时候,自动提示对象属性的名称是怎么做到的

2019-08-30 10:27:47 +08:00
 12tall

就是类似于electron 中的这种效果

mainWindow = new BrowserWindow({
    show: false,  // 在输入到 s 的时候就会自动提示 show 或其他 s 开头的属性
    width: 540,
    height: 540,
});

我在定义函数的时候指定了默认参数,好像可以实现,不知道是不是正规路数。。。。

var Test = function (cfg = { enabled: false }) {

}
3231 次点击
所在节点    JavaScript
5 条回复
codehz
2019-08-30 10:30:32 +08:00
用了 typescript,然后声明了参数的类型
iyeatse
2019-08-30 10:53:34 +08:00
纯 js 的话,可以试试 jsdoc
https://jsdoc.app/tags-param.html
12tall
2019-08-30 11:04:26 +08:00
@codehz 谢谢,学习下
12tall
2019-08-30 11:12:30 +08:00
@iyeatse 嗯嗯,这个感觉好理解啊,学习了,感谢!

```js
/**
* Assign the project to an employee.
* @param {Object} employee - The employee who is responsible for the project.
* @param {string} employee.name - The name of the employee.
* @param {string} employee.department - The employee's department.
*/
Project.prototype.assign = function({ name, department }) {
// ...
};
```
lllllliu
2019-08-30 11:22:53 +08:00
@12tall 还阔以支持一键生 doc

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/596439

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX