当我尝试在 v0.10.25 版本的 Node 服务器中使用 endsWith 检查字符串模式时,它抛出了一个错误,
Object ''''''' has no method 'endsWith'
然后我从这个链接中发现,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith ,那个 String.prototype.endsWith 只会来自 ECMA6。 那么, Node v0.10.25 实现了什么 ecma 版本?哪个 nodejs 的 future 版本,我可以期望与 ECMA6 兼容?
最佳答案
很明显,如果不是 ES6,它将在 ES5 或 javacript 的当前迭代中实现。另外,您可以自己编写,而不是等待它
String.prototype.endsWith = String.prototype.endsWith || function(str){
return new RegExp(str + "$").test(str);
}
关于javascript - Node v0.10.25 中的字符串原型(prototype)没有 'endsWith',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27599537/