cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Berens" <rber...@osirion.nl>
Subject Problem with locking related to locking the JS global scope
Date Fri, 24 Dec 2004 11:58:28 GMT
I ran into a problem related to locking the JS global scope.
I have the following use case:

I have a large number of scripts possible, which I don't want to include in
the sitemap, as I want a mechanism by which I can just introduce a new
script in my website content, which is automatically detected without
modifying the sitemap. Therefore in the sitemap I just include one script:

<map:flow language="javascript">
  <map:script src="main.js"/>
</map:flow>

In this main script I do the actual load of the applicable script. The
sitemap looks something like this (simplified for this purpose):

<map:match *.js>
  <map:call function="_loadScript">
    <map:parameter name="script" value="{0}"/>
    <map:parameter name="function" value="doIt"/>
  </map:call>
</map:match>

Now main.js looks like this (again simplified):

function _loadScript() {
    cocoon.load(cocoon.parameters["script"]);
    this[cocoon.parameters["function"].call(this);
}

and the specifc script to be loaded looks like:

var someVar;

function doIt() {
    do something .....
}


This worked fine until the JS global scope was locked in cocoon 2.1.6. As
the load does not take place in the global part of main.js but in the
function _loadScript, I get the error:
Implicit declaration of global variable .... forbidden. Please ensure all
variable are explicitely declared with 'var'.
If I have the 'someVar' declaration in the script the message occurs for
'someVar'. If I take it out, it occurs for 'doIt'. The reason this message
occurs that the script is not loaded from the global part of main.js, but
from within a function. I can bypass the problem by adding

var someVar
var doIt

to main.js, but this would require me to know all variables and function
names in the dynamically loaded script beforehand thereby loosing the
flexiblity I need. In my sitemap I want to the function name to be flexible
and I want ot be able to add any variables and functions to my specific
script.

I propose that in the use case no error is reported. I tried to find out how
to handle this in flow, but could not determine how.

Can anyone help me or comment on this?

Regards,

Rob Berens
Osirion B.V.
Gagelveld 41
6596 CC  Milsbeek
The Netherlands
Tel: +31 (0)485-54 02 03
Fax: +31 (0)485-54 02 04
E-mail: rberens@osirion.nl



Mime
View raw message