javascript - How to extract comments from Object literals in javascript
问题描述
I'm trying to extract comments from different javascript objects. In the case of a function, I can easily do it by using .toString and then apply a regex to the function output. However, If the object is an object literal with comments I can't extract the comments because of course toString returns [object Object]
I've tried use Object.toSource
but that seems to strip out the comments :/. I'm wondering if there is any smart hack to do this.
I release I could wrap the object literal in a function and then call .toString
but I don't have access to the where it is defined - I am just passed the reference.
For clarity:
const myFunction = () => {
// I can extract this
return 'foo'
}
const myObject = {
// I can't extract this
foo: 'bar'
}
Is there any way to do this?
解决方案
在运行时这是不可能的。您应该使用文件解析器或类似 jsDoc 的东西会更好。
推荐阅读
- classification - 如何从 mclust 获取分类分配?
- python - 如何改进 LOCUST 报告界面?
- matlab - 使用相同的符号名称来构建具有符号变量数组的方程组
- java - 如何将篮子的总成本加起来?
- php - 如何用不同的项目签入/结帐汇总小时和分钟
- objectoutputstream - 侦听 DefaultTableModel 以了解其数据的任何更改,然后将其保存到文件中
- flutter - 如何在另一个动画以相同的速度(持续时间)完成之前运行动画
- javascript - 如何停止 JS 滚动到顶部功能覆盖导航栏中的链接
- javascript - 如何在 Vuetify 文本字段中获取键和值?
- c++ - 将错误从 const 字符串转换为 const uint8_t*