admin管理员组文章数量:1289529
I have a piece of code that runs on the browser. There's a library loaded from a CDN that puts some variables on the global scope. How can I document the type of that variable?
For example
index.hmtl => puts globalVariable
on the global scope
...
<script src="//cdn.library/library.js"></script>
...
index.js => uses globalVariable
/**
* @type {SomeType} globalVariable
*/
const foo = globalVariable()
Something like that so I can specify the type of globalVariable
. Is that possible?
I have a piece of code that runs on the browser. There's a library loaded from a CDN that puts some variables on the global scope. How can I document the type of that variable?
For example
index.hmtl => puts globalVariable
on the global scope
...
<script src="//cdn.library./library.js"></script>
...
index.js => uses globalVariable
/**
* @type {SomeType} globalVariable
*/
const foo = globalVariable()
Something like that so I can specify the type of globalVariable
. Is that possible?
1 Answer
Reset to default 7Typecasting and the window
global can be your friend here.
To cast:
const globalVariable = /** @type {someType} */ (window.globalVariable);
To modify the window
global add an externs file that contains:
/** @type {someType} */
window.prototype.globalVariable = function() {};
本文标签: javascriptHow to document the type of a global variable with JSDOCStack Overflow
版权声明:本文标题:javascript - How to document the type of a global variable with JSDOC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741431408a2378383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论