Node.js v6里有哪些新东西?
Posted Node全栈
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Node.js v6里有哪些新东西?相关的知识,希望对你有一定的参考价值。
Node.js v6里有哪些新东西?
https://blog.risingstack.com/whats-new-in-node-v6/
性能提升
模块加载性能比当前的LTS(Node.js v4)版本要快上4倍,不要误解是整体快4倍. 主要体现在应用引导入口状态的时间减少
Related PRs:
Updated V8 engine
安全提升
Math.random - improved security, but note, that it is still not cryptographically secure
For more information, check:
New Buffer API to reduce the risk of bugs and vulnerabilities leaking into applications
Related PRs:
新的ES6特性
Default function parameters
function multiply(a, b = 1) { return a * b
}
multiply(5) // 5
Learn more on the default function parameters.
Rest parameters
function fun1(...theArgs) { console.log(theArgs.length)
}
fun1() // 0
fun1(5) // 1
fun1(5, 6, 7) // 3
Learn more on the rest parameters.
Spread operator
// before the spread operator
function myFunction(x, y, z) { }
var args = [0, 1, 2]
myFunction.apply(null, args)
// with the spread operator
function myFunction(x, y, z) { }
var args = [0, 1, 2]
myFunction(...args)
Learn more on the spread operator.
Destructuring
var x = [1, 2, 3, 4, 5]
var [y, z] = x
console.log(y) // 1
console.log(z) // 2
Learn more on destructuring.
new.target
function Foo() { if (!new.target) throw 'Foo() must be called with new' console.log('Foo instantiated with new')
}
Foo() // throws "Foo() must be called with new"
new Foo() // logs "Foo instantiated with new"
Learn more on the new.target.
Proxy
The Proxy object is used to define custom behavior for fundamental operations.
var handler = { get: function(target, name){ return name in target ? target[name] : 37 }
};
var p = new Proxy({}, handler)
p.a = 1 p.b = undefined
console.log(p.a, p.b) // 1, undefined
console.log('c' in p, p.c) // false, 37
Learn more on proxies.
Reflect
Reflect is a built-in object that provides methods for interceptable javascript operations.
Learn more on reflect.
Symbols
A symbol is a unique and immutable data type and may be used as an identifier for object properties.
Symbol("foo") === Symbol("foo"); // false
Learn more on symbols.
尝试一下热乎的 Node.js v6吧
If you are using nvm, you only have to:
$ nvm install 6
If you for some reason cannot you nvm, you can download the binary from the official Node.js website.
什么时候可以迁移到Node 6呢?
今年10月份 Node.js v6 会升级到LTS 版本 - 那时你就可以正式的产品环境使用了,目前还不能确定完全稳定。
全文完
如果想参与评论,请点击原文链接,进入国内最专业的cnode论坛
以上是关于Node.js v6里有哪些新东西?的主要内容,如果未能解决你的问题,请参考以下文章
AWS Lambda 导出类在 node.js v6.4 中有效,但在 node.js v4.3 中无效,如何解决这个问题? [复制]
Node.js v6.6.0 (Current) 发布,大幅度更新