Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS define() doesn't call callback

I'm wondering why...

<script type="text/javascript">
    define('test', [], function() {
        alert('Done') ;
    }) ;
</script>

... doesn't work.

I'm using my own Framework which uses RequireJS if available, and calls define(name, dependencies, callback) ; for every module loaded that requires another one. But sometimes modules don't have dependencies, so dependencies is an empty array.

Besides I know that...

require([], function() {
    alert('Done') ;
}) ;

... works fine.

Could you explain me why the first method doesn't work ? Thanks.

like image 341
Tot Avatar asked Sep 25 '13 19:09

Tot


1 Answers

Until you require the 'test' module, it will obviously not get called.

<script type="text/javascript">
    define('test', [], function() {
        alert('Done') ;
    }) ;
    require(['test'], function() {});
</script>
like image 147
Simon Boudrias Avatar answered Sep 23 '22 15:09

Simon Boudrias