Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

initialization of array #375

Open
andekande opened this issue May 24, 2013 · 1 comment
Open

initialization of array #375

andekande opened this issue May 24, 2013 · 1 comment

Comments

@andekande
Copy link
Contributor

Today I learned a lesson. Consider this C# code:
List a = new List();
a.Add(1);
List b = new List(a);

While used to do it like this to get a fresh copy of the list, in JavaScript this happens:
var a = new Array()
a.push(1)
var b = [a]

So there is a new Array which 1st item is the Array to be copied.
I'm using it wrong, I know, it should be:
List b = a.Splice(0);

But hey, couldn't be this done by the compiler for me?

@andekande
Copy link
Contributor Author

Another stumbling block which makes looking for errors time consuming is this:
List a = new List(1, 2, 3);
List b = new List();
b.AddRange(a);

Translates as well into an push(), whereas b becomes [[a]] and not [1, 2, 3] !
Considering the difference to the original .Net behaviour isn't it something that should be adressed?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant