加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

actionscript-3 – 如何在ActionScript 3中创建数组的浅表副本

发布时间:2020-12-15 01:49:04 所属栏目:百科 来源:网络整理
导读:var a:Array = ["a","b","c"];var b:Array;/* insert code here to copy 'a' and assign it to 'b'*/ 解决方法 摘自As3参考指南: The Array class has no built-in method for making copies of arrays. You can create a shallow copy of an array by call
var a:Array = ["a","b","c"];

var b:Array;

/* insert code here to copy 'a' and assign it to 'b'*/

解决方法

摘自As3参考指南:

The Array class has no built-in
method for making copies of arrays.
You can create a shallow copy of an
array by calling either the concat()
or slice() methods with no arguments.
In a shallow copy,if the original
array has elements that are objects,
only the references to the objects are
copied rather than the objects
themselves. The copy points to the
same objects as the original does. Any
changes made to the objects are
reflected in both arrays.

如果你在concat和slice之间做出选择,Concat将是你要走的路,因为concat在性能方面更快.

在此处阅读有关此主题的更多信息:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7ee7.html

澄清:

private function shallowCopy():void{
        var a:Array = ["h","e","l","o"];
        var b:Array = a.concat(); 

        trace("Shallow copy:");
        trace("Before delete: " + a);
        trace("Before delete: " + b);
        delete a[0];
        trace("After delete: " + a);
        trace("After delete: " + b);            
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读