Why not just test it?
String.prototype.repeat = function(n) {
return new Array(n + 1).join(this);
}
var s = "x".repeat(Math.pow(2, 23)) + "y";
document.write(s.charAt(s.length - 1));
Anything larger in IE and I get an Out of memory error trying to *construct* the
string, but that's probably due to the implementation I'm using (constructing
the array and using .join()). I was able to get Firebird up to
..repeat(Math.pow(2, 22)) before it completely gave up the ghost and stopped
responding. Interestingly enough, Opera 7.21 seemed particularly adept at this
task, and was able to construct a string 2^31 long almost instantly.
As for any limit in C having an effect on a limit in JavaScript, that's silly. A
String in JavaScript is an object containing a set of unicode characters, as
well as various properties and methods, isn't a string in C simply an area of
memory at begun at some location, and terminated by a \0? So why should there be
an artificial limit in C at all?
Considering the modern browsers I tested were capable of setting and retrieving
the last character of a string at least 2^20 long, I doubt you'll have any
problems for the foreseeable future.
"Wade G. Pemberton" wrote:
Richard Cornford wrote:
I can tell from experience it's not 1024. The last string I used was over
23K bytes. However, I just wanted to make sure the limit wasn't something
like 2^16, which I'll collide with shortly. It's just a packing script
to export to MS Access from webdom. Since javascript has C as it's
progenitor, that's probably the limit. I've forgotten that limit, and
there's no book handy.
Wade
"Douglas Crockford" <no****@laserlink.net> wrote in message
news:9a**************************@msgid.meganewsse rvers.com...
<snip>... . The maximum length with will be implementation-specific. ...
In microsoft.public.scripting.jscript, Michael Harris
(Microsoft.MVP.Scripting), who might be expected to know, quoted:-
<quote Message-ID: <#C**************@TK2MSFTNGP12.phx.gbl>
In JScript, variant string variables have the same limit as in VBScript,
up to 2^31 characters.
String *literals* (as in "this is a literal") have (IIRC) a limit ~2^10
(1024) characters.
</quote>
- for the JScript implementation.
Richard.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html