如何在 ActionScript 3 中创建数组的浅表副本
var a:Array = ["a","b","c"];
var b:Array;
/* insert code here to copy 'a' and assign it to 'b'*/
var a:Array = ["a","b","c"];
var b:Array;
/* insert code here to copy 'a' and assign it to 'b'*/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
摘自 As3 参考指南:
如果您在连接和切片之间进行选择,连接将是最佳选择,因为连接在性能方面更快。
在此处阅读有关该主题的更多信息:http://help.adobe.com /en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee7.html
澄清:
Taken from the As3 reference guide:
Concat would be the way to go if you choose between concat and slice since concat is faster in terms of performance.
Read more about the subject here: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee7.html
To clarify:
有问题的行:
The line in question:
如果数组仅包含字符串或数字值,则足以制作“浅”副本,如 Adam 和 rzetterberg 所描述的那样。
如果数组包含其他数组或对象/类实例等,那么如果您需要内部的所有对象都是唯一的而不仅仅是引用,则应该进行深层复制。您可以通过以下方式实现:
这对于复制没有任何 concat 或 splice 方法的对象也很有用。
If the array contains just string or number values, it's enough to make a "shallow" copy, as described by Adam and rzetterberg.
If the array contains other arrays or objects/class instances, etc. then you should make a deep copy if you need all of the objects inside to be unique as well and not just references. You can achieve that with:
This is also useful for copying Objects, which don't have any concat or splice methods.