在 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 objectsBennyLava: they're just not enumerable
所以答案是Object.getOwnPropertyNames(String.prototype)
。
关于javascript - 查看Node.js String.prototype的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12536510/