admin管理员组

文章数量:1023221

I'm trying to import a set of coordinates from an external javascript. I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?

This is my code:

function CreateArray() {   
return new Array(
...
...
...
78.740 elements later
...
); }

I'm trying to import a set of coordinates from an external javascript. I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?

This is my code:

function CreateArray() {   
return new Array(
...
...
...
78.740 elements later
...
); }
Share Improve this question asked Sep 12, 2010 at 11:22 alexalex 1,2781 gold badge17 silver badges38 bronze badges 2
  • Whilst they exist, never use Array or Object constructors, use literals over 'new Array/Object'. – BGerrissen Commented Sep 12, 2010 at 11:48
  • 1 BGerrissen: that's a little dogmatic. I agree that literals are generally preferable, but there's occasions when the Array constructor is useful. For example: var hugeString = new Array(1e6).join("x"); – Tim Down Commented Sep 12, 2010 at 15:15
Add a ment  | 

2 Answers 2

Reset to default 9

Try array literal, it worked for me (tested with success for million items):

function CreateArray() {   
    return [
        ...
    ];
}

You may be running into memory limitations, not sure.

How about trying to push() the values into an array instead of initializing all of them all at once? Break it into smaller chunks of data to add to the array instead of adding it all in one mand.

var a = [];
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
// etc...
return a;

I'm trying to import a set of coordinates from an external javascript. I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?

This is my code:

function CreateArray() {   
return new Array(
...
...
...
78.740 elements later
...
); }

I'm trying to import a set of coordinates from an external javascript. I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?

This is my code:

function CreateArray() {   
return new Array(
...
...
...
78.740 elements later
...
); }
Share Improve this question asked Sep 12, 2010 at 11:22 alexalex 1,2781 gold badge17 silver badges38 bronze badges 2
  • Whilst they exist, never use Array or Object constructors, use literals over 'new Array/Object'. – BGerrissen Commented Sep 12, 2010 at 11:48
  • 1 BGerrissen: that's a little dogmatic. I agree that literals are generally preferable, but there's occasions when the Array constructor is useful. For example: var hugeString = new Array(1e6).join("x"); – Tim Down Commented Sep 12, 2010 at 15:15
Add a ment  | 

2 Answers 2

Reset to default 9

Try array literal, it worked for me (tested with success for million items):

function CreateArray() {   
    return [
        ...
    ];
}

You may be running into memory limitations, not sure.

How about trying to push() the values into an array instead of initializing all of them all at once? Break it into smaller chunks of data to add to the array instead of adding it all in one mand.

var a = [];
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
// etc...
return a;

本文标签: javascript too many constructor argumentsStack Overflow