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
2 Answers
Reset to default 9Try 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
2 Answers
Reset to default 9Try 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
版权声明:本文标题:javascript too many constructor arguments - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745543490a2155289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论