簡體   English   中英

節點v0.10.25中的字符串原型沒有'endsWith'

[英]String prototype in node v0.10.25 does not have 'endsWith'

當我嘗試在版本為v0.10.25的節點服務器中使用endsWith檢查字符串模式時,拋出了錯誤,

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?

顯然,如果沒有ES6,它將在ES5或jaavacript的當前迭代中實現。 另外,不用等待,您可以編寫自己的

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

http://kangax.github.io/compat-table/es6/在這里您可以找到ecma-script-6的兼容性表。

並閱讀此答案https://stackoverflow.com/a/13352093/3556874 您可以通過這種方式激活節點和聲標記節點--harmony app.js ,以使節點與字符串endsWith兼容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM