Hey, welcome back in this lesson, we're going to continue to construct and work with the dorm content
loaded and as we saw last time, that whenever the page, the document object loads, then it fires
off an event listener that is listening for the dorm content to be loaded and it runs the code that's
contained within here.
So what I want to do in this lesson is extend on what we did in the last lesson.
We're going to actually create a standalone app object that's going to run whenever the page gets loaded.
And this is going to be where we're going to contain the core of our code.
And this is also going to allow us to separate out the application from any other Java scripts in case
for reusing some of the variable names and so on.
It's not going to conflict as we're gonna be wrapping it in an object called app.
So let's set that up within the script file.
And then we're going to run app whenever the page loads.
So creating an app and it's going to be a function.
It's going to be actually a self invoking function.
That's going to run a particular file whenever the page loads.
So it's going to be returning back an iron I.T. function.
So let's create that contained within the app function.
And I NIST is going to be the first initial initializing function that's going to run.
And then within here, we can just simply put, I an I.T. ready.
And that means that all of the content and we're gonna be using ITC to construct our gameboard in the
upcoming lessons.
So it's going to be an important function.
And of course, we do want to return something.
And that's what we're going to be returning back.
So it's going to contain all of the construction of our Web page.
And keeping it within a separate variable called app.
That's going to be separate from the rest of the JavaScript code.
And all of the OP contents are going to be scripts sitting in script.
J.
S.
And the only connection is going to be with an index dot h Timal.
Where we're going to be loading the script, G.S. file.
And then whenever the DOM content loads that we're going to connect to up.
So doing return, you're going to return back an object.
And that's going to be iron I.T..
And we're going to invoke the function iron.
And this is expecting a function to be associated with it.
So it's why we're not using the rounded brackets.
Otherwise, we'd be invoking the function down here.
And we don't want to be invoking the function on the return.
We just want to be associating identity with the same function name.
So that's where we're returning that information back.
And we do want OP to be self invoking.
So we're going to simply have the rounded brackets which indicate that the application is going to invoke.
And that means that whenever we have the DOM content loaded instead of running function, we're going
to connect it to the app.
I indictee object and it's going to run the app by NATO function.
And remember, this is self invoking.
That's where we don't need the rounded brackets because we've placed it within app.
So let's try that and refresh the page.
And now we've got instead of Piech ready, we've got iron I.T. ready.
So that means that the app object is up and running and it's returning back the contents of iron I.T.
and within iron I.T. is where we're gonna set all of the document content.
And that's coming up in the next lesson, where we're going to construct some H.T. Amelle for the page.
So that's going to be visible as well as setup some game variables that we're going to be using within
the app object.
And the reason for making it this way is, again, to separate out any of this JavaScript contained
within script J.
S from the regular pages.
As you might have several different JavaScript libraries and you don't want any interference between
the app object and the function names with it here.
That might be affecting the rest of the JavaScript code on the Web page.
So there's a completely separate set out and provides a nice, neat place to build our code within.
And this is gonna be a lot of JavaScript.
We're gonna be focusing only on JavaScript.
So the upcoming lessons, we're gonna construct everything using JavaScript.
So that's coming up next.