javascript - 查看Node.js String.prototype的方法?

标签 javascript string node.js

在 Node.js REPL 中,如果您键入 String.prototype,将返回一个空对象:{}。但是,如果您在 Chrome JavaScript 控制台中键入它,则会返回一个包含预期函数名称和函数的对象。

为什么 Node.js 没有表现出这种行为?如何访问 Node.js 中的原生字符串函数?

最佳答案

根据 FreeNode/#node.js 上的 IRC 用户

BennyLava: Object.getOwnPropertyNames(String.prototype)

jmar777: because in the REPL you basically get the result of calling toString() on the result, whereas the chrome console has some fancy interactive display of objects

BennyLava: they're just not enumerable

所以答案是Object.getOwnPropertyNames(String.prototype)

关于javascript - 查看Node.js String.prototype的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12536510/

相关文章:

excel - VBA:转换数字格式/刷新单元格

javascript - 咕噜声 : Location URL app with period

javascript - 如何使文本区域内容以与输入相同的方式在溢出时水平滚动? (没有 "jumps")

javascript - 使用 moment.js 的 dd-MM-yyyy 日期格式

javascript - 为什么scroll事件不冒泡?

javascript - 相对于页脚调整高度的固定位置 div

c - 如何在 C 中连接字符串?

使用字符串函数进行 C++ 循环

javascript - 删除node js中某个目录下名称以某个字符串开头的所有文件

javascript - 如何处理 catch block 然后处理 Promise