Search code examples
javascriptfunctiondojo

What triggers execution of the second parameter to require() in the "Hello Dojo!" tutorial


I was working my way through the "Hello Dojo!" tutorial found here.

The primary logic for this tutorial is found as a function passed to the require() call in the header, but I can't figure out what triggers it:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Tutorial: Hello Dojo!</title>
</head>
<body>
	<h1 id ="greeting">Hello</h1>
	<!-- load Dojo -->
	<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js" 
		data-dojo-config="async: true"></script>
		
	<script>
<!-- how is this calling!? -->	
		require([
			'dojo/dom',
			'dojo/dom-construct'
		], function(dom,domConstruct) {
			var greetingNode = dom.byId('greeting');
			domConstruct.place('<em> Dojo!</em>', greetingNode);
			})
	</script>
</body>
</html>

I understand how the logic within that function is called - obtaining a reference to the greeting element and then appending an em node to it - but I can't figure out why/how the code inside the function is executed to begin with!


Solution

  • You have: require(...)

    So you call require and pass it pass an array of strings and a function as arguments.

    require (or a function it calls later) is responsible for calling the second argument.