5

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.

2
  • 2
    Is there anything that requires your test module? If not, it won't be loaded (executed). Commented Sep 25, 2013 at 19:31
  • Yes it will, only once required (see answer from @Simon Boudrias). Commented Sep 25, 2013 at 20:04

1 Answer 1

7

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.