Versio

[JS]Dynamic import/init

Overzicht Reageren

Jacco Engel

Jacco Engel

18/06/2009 11:11:00
Quote Anchor link
Mensen,

ik probeer een js import te maken, heb dit op de volgende manier gedaan:

index.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
<html>
    <head>
    </head>
    <body>
    
    <span id="JS_FILE_LIST">
    </span>
    <script type="text/javascript" src="init.conf.js"></script>
    <script type="text/javascript">
        $import('Test') ;
    </script>
    </body>
</html>


init.conf.js
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
function $import(File)
{
    var script = document.createElement('script') ;
    script.type = 'text/javascript' ;
    script.src = File+'.class.js' ;
    document.getElementById('JS_FILE_LIST').appendChild(script);
    
        eval('var cls'+File+' = '+(new String(File+'()'))+';');
        eval('cls'+File+'.init()');

}


Test.class.js
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
var Test = function()
{
    this.init = function()
    {
    },
    
    this.doe = function()
    {
        alert('ik ga al') ;
    }
}


Nu krijg ik alleen elke keer de error 'Test is undefined'...

Zit er al een poosje naar te staren maar zie het even niet... Iemand hier die het foutje wel ziet?
 
PHP hulp

PHP hulp

25/05/2012 02:00:20
Gesponsorde koppelingen:
 
De VeeWee

de VeeWee

18/06/2009 13:24:00
Quote Anchor link
Laat die "," achter de eerste functie weg.
bij de Objects in javascript moet er een "," tussen de functies en variabelen staan.
Bij Functions moet er geen komma staan. Gelijkaardig als de php classes.
 
Jacco Engel

Jacco Engel

18/06/2009 13:30:00
Quote Anchor link
En dat is van toegevoegde waarde omdat?
 



Overzicht Reageren