简体   繁体   English

我如何检查节点版本是否支持javascript方法

[英]How can i check if a javascript method is supported by my node version

I want to use reduce() javascript method in my node application. 我想在我的节点应用程序中使用reduce() javascript方法。 My node version is 4.2.6. 我的节点版本是4.2.6。 How can I check if I can use this method without breaking my application. 如何检查我是否可以在不破坏应用程序的情况下使用此方法。

Thank you. 谢谢。

There are two approaches on how to test javascript methods supporting. 有两种方法可以测试javascript方法的支持。

1. Compatibility tables. 1.兼容性表。

For example, this one . 例如, 这个 Searching for Array methods rows, since the .reduce is a ES5 extension of the Array.prototype , we see that Node 4 supports it well. 搜索Array methods行,因为.reduceArray.prototype的ES5扩展,我们看到Node 4很好地支持它。 Node.geen tables also work. Node.geen表也​​可以工作。 So, the particular answer for Node 4.2.6 is yes , it supports Array.prototype.reduce . 因此,对Node 4.2.6的特殊回答是yes ,它支持Array.prototype.reduce

2. Manual check. 2.手动检查。

Also, depends on your needs, you may check it programmatically right in the code: 另外,根据您的需求,您可以在代码中以编程方式对其进行检查:

if (!Array.prototype.reduce) {
  // no .reduce()
}

This could be useful for example if you want to polyfill missing method manually. 例如,如果您想手动填充缺少的方法,这可能会很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM