Loading array1.js from xx.js file

S

Sunouchi

Dear experts, I would like to know how to load an array in a '.js'
file from another '.js' file

With <script src="pictitle\array1.js"></script> I can load that array
from a html file.

However I want to load array1.js from another javascript file (xx.js)
because in xx.js a 'random' number is calculated. On the result of
that random number I want to load array1.js or array2.js or array3.js
or even more arrays. (Every array is more than 1,000 elements large)

How can I do that?

Thanks in advance
Sunouchi
 
A

Asen Bozhilov

Sunouchi said:
I would like to know how to load an array in a '.js'
file from another '.js' file

Depends from environment. This functionality usually is provided by
host and wrapped in host object. In browser environment you can do it,
in different ways. With dynamic insert script tag, XHR and iframe.
However I want to load array1.js from another javascript file (xx.js)
because in xx.js a 'random' number is calculated. On the result of
that random number I want to load array1.js or array2.js or array3.js
or even more arrays. (Every array is more than 1,000 elements large)

And what is your benefit from all of this? Why do you want to do it?
If you answer of that questions, you can find much-more better design.
If you care about memory consumption from arrays, you can use
different approach. Wrap array initializations in `function' object
and leave garbage collector to care about memory consumption. See
above:

function array1()
{
return [1, 2, Math.pow(2, 31)];
}

array1()[0];

Get the value of property `0', and mark returned `object' for garbage
collection, because there are no any references to that `object'.
 
S

Sunouchi@

Hello,
And what is your benefit from all of this? Why do you want to do it?

There is no real benefit at this moment. It works fine when I load the
arrays from the default.html. However, I want a new approach and I
want to know whether it is possible, to load a 'js' from a running
'js'. Just to do new things, like: l'art pour l'art, that kind of
stuff.

e.g. I discorvered that it works perfectly well with
document.write("<script src='pictitel\/titel_G_01.js'></script>");
alert("Some text");
But it works only in combination with the alert and only in Firefox.
Otherwise I get: 'picArray' is not defined.

Thanks for your attention
Sunouchi



Sunouchi said:
I would like to know how to load an array in a '.js'
file from another '.js' file

Depends from environment. This functionality usually is provided by
host and wrapped in host object. In browser environment you can do it,
in different ways. With dynamic insert script tag, XHR and iframe.
However I want to load array1.js from another javascript file (xx.js)
because in xx.js a 'random' number is calculated. On the result of
that random number I want to load array1.js or array2.js or array3.js
or even more arrays. (Every array is more than 1,000 elements large)

And what is your benefit from all of this? Why do you want to do it?
If you answer of that questions, you can find much-more better design.
If you care about memory consumption from arrays, you can use
different approach. Wrap array initializations in `function' object
and leave garbage collector to care about memory consumption. See
above:

function array1()
{
return [1, 2, Math.pow(2, 31)];
}

array1()[0];

Get the value of property `0', and mark returned `object' for garbage
collection, because there are no any references to that `object'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top