分配给数组的语法 [英] syntax for assigning to an array

查看:106
本文介绍了分配给数组的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,如果函数返回一个数组,那么捕获

的返回值是相当常见的:


<?php

列表($ foo,$ bar,$ baz)= some_function_that_return_an_array();

?>


在Javascript中,相同的(可接受的)代码是否会这样?


[foo,bar,baz] = some_function_that_return_an_array();


我通常运行我的代码通过JSLint作为一个快速的健全性检查,但这个

表达式使它死亡。显然它是JSLint中的一个解析错误,但是我想要确保我没有完全关闭

。谢谢。

In PHP, if a function returns an array it''s fairly common to capture
its return values like this:

<?php
list($foo, $bar, $baz) = some_function_that_return_an_array();
?>

In Javascript, would the equivalent (acceptable) code be this?

[foo, bar, baz] = some_function_that_return_an_array();

I usually run my code through JSLint as a quick sanity check, but this
expression makes it die. Clearly it''s a parsing bug in JSLint, but I
also wanted to make sure that I wasn''t doing something completely off
the wall. Thanks.

推荐答案

foo,


bar,


baz )= some_function_that_return_an_array();

?>


在Javascript中,等效(可接受)的代码是否会这样?


[foo,bar,baz] = some_function_that_return_an_array();


我通常通过JSLint运行我的代码作为快速健全性检查,但是这个

表达使它死亡。显然它是JSLint中的一个解析错误,但是我想要确保我没有完全关闭

。谢谢。
baz) = some_function_that_return_an_array();
?>

In Javascript, would the equivalent (acceptable) code be this?

[foo, bar, baz] = some_function_that_return_an_array();

I usually run my code through JSLint as a quick sanity check, but this
expression makes it die. Clearly it''s a parsing bug in JSLint, but I
also wanted to make sure that I wasn''t doing something completely off
the wall. Thanks.


这篇关于分配给数组的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆