美文网首页
初探深入浅出ES6之多重返回值

初探深入浅出ES6之多重返回值

作者: Kelly_8d35 | 来源:发表于2017-12-21 12:58 被阅读0次

JS中尚未整合多重返回值的特性,但是无须多此依据,因为你自已就可以返回一个数组并将结果解构:

function retrunMultipe()

{

return [100,2100];

}

var [foo,bar]= retrunMultipe ();

或者,你可以用一个对象作为容器并为返回值命名

function returnMultipleValues() {

return{

fooMultipe:1,

baMultiper:2

};}

var{ fooMultipe,baMultiper} =returnMultipleValues();

这两个模式都比额外保存一个临时变量要好得多

渐渐的在使用的语言中加入解构这个新特性,它可以让代码变得更加精简整洁。

相关文章

网友评论

      本文标题:初探深入浅出ES6之多重返回值

      本文链接:https://www.haomeiwen.com/subject/qxprwxtx.html