1

COnsider the following example;

require(["dojo/dom", "dojo/domReady!"], function(dom){
    dom.byId("helloworld").innerHTML = "Hello New World!";
  });

My question is for the dependencies, while we refer 2 JS files, we just have one parameter as the callback (so assume it maps to the first dependent file)

But my question is what usage does it seem appropriate. Ideally I thought it should be always one-to-one mapped.

My question is not actually to understand about the DOJO usage...but I am looking to understand the Javascript concept behind the Mismatch of parameters/callback.

copenndthagen
  • 49,230
  • 102
  • 290
  • 442

1 Answers1

0

The dojo/domReady! is a loader plugin that has the effect that the inner function is executed after the DOMContentLoaded event on the document - this makes sure that DOM elements are in place that you want to modify. So this dependency doesn't really have a value but only causes a side effect. It's essentially the same as if you would do this with jQuery:

require("dojo/dom", function (dom) {
    // Here the dom element I'm looking for is not guaranteed to
    // to be available ...
    $(document).ready(function() {
        // ... but here is
        dom.byId("helloworld").innerHTML = "Hello New World!";
    });
});
mfeineis
  • 2,607
  • 19
  • 22