节点v0.10.25中的string原型没有“endsWith”

当我试图检查使用endsWith在节点服务器版本v0.10.25一个string模式,它抛出一个错误,

Object ''''''' has no method 'endsWith' 

然后我发现从这个链接, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith,String.prototype.endsWith将只来自ECMA6。 那么,ecma版本节点v0.10.25实现了什么? 哪个nodejs的未来版本,我可以期望是ECMA6兼容?

http://kangax.github.io/compat-table/es6/这里可以findecma-script-6的兼容性图表。

并阅读这个答案https://stackoverflow.com/a/13352093/3556874 。 你可以这样激活节点和声标志节点--harmony app.js ,使节点与stringendsWith兼容

很明显,如果不是ES6,它将在ES5中实现,或者是当前的jaavacript迭代。 而不是等待它,你可以写你自己的

 String.prototype.endsWith = String.prototype.endsWith || function(str){ return new RegExp(str + "$").test(str); }