Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript too many constructor arguments

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
...
); }
like image 269
alex Avatar asked Sep 12 '10 11:09

alex


People also ask

How many constructor parameters is too many?

In the Java edition of Building Maintainable Software, Joost Visser advises keeping the number of parameters to no more than four. The same guideline probably applies to almost all other programming languages, like C#, Scala and even FORTRAN and COBOL.

How do you avoid too many arguments?

There are two techniques that can be used to reduce a functions' arguments. One of them is to refactor the function, making it smaller, consequently, reducing the arguments' number. The Extract Method technique can be use to achieve this goal.

How many parameters can a constructor take?

This method has four parameters: the loan amount, the interest rate, the future value and the number of periods.


1 Answers

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

function CreateArray() {   
    return [
        ...
    ];
}
like image 91
pepkin88 Avatar answered Sep 18 '22 21:09

pepkin88