How do I call a function using requirejs?
It's an overly simple question, but surprisingly enough no tutorial or example has been able to help me so far.
This is the code in my html file.
...
<script src = "stuff.js"></script>
<button onclick="doStuff(4, 2)";>DoStuff</button>
...
This is my require js.
define(["jquery"], function ($) {
function doStuff(a, b) {
//does some stuff
}
});
Why does this not work? I get ReferenceError: doStuff is not defined
doStuffwill only exist within the scope of the require callback. The reason there's no tutorial on it is because you shouldn't be adding this sort of dependency in inline event handlers. Keep your JS out of your HTML.