Created
November 1, 2012 02:30
-
-
Save mbolt35/3991279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* So, if I want to create a new Vector.<int> that | |
* appends 3, 2, 1 without modifying the original, | |
* I need to create *another* new Vector.<int>, just | |
* to pass the values to concat(). That's one extra | |
* Vector.<int> instantiation. Three total Vector.<int> | |
* objects, while only 2 should be needed: | |
* -- One, the original vec:Vector.<int>. | |
* -- Two, the new <int>[ 3, 2, 1 ] to pass the concat() | |
* parameter. | |
* -- Three, the result:Vector.<int> | |
*/ | |
var vec:Vector.<int> = new <int>[ 1, 2, 3 ]; | |
var result:Vector.<int> = vec.concat( new <int>[ 3, 2, 1 ] ); | |
trace(result); | |
/** | |
* Or, we can save the trouble of creating an extra | |
* Vector.<int> by shallow copy and appending the | |
* 3, 2, 1 manually: | |
*/ | |
var vec:Vector.<int> = new <int>[ 1, 2, 3 ]; | |
// Shallow Vector.<int> copy | |
var result:Vector.<int> = vec.concat(); | |
result.push(3, 2, 1); | |
trace(result); | |
// Outputs: 1,2,3,3,2,1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment