first thing we start off with, is we create a variable here called Render Engine
Class. And you define a variable by starting with the key word var, and then the
variable name. And then you say equals, whatever you would like it to be equal
to. In this case we use an opening brace, to indicate that we'd like this to be
a javascript object. This is the object literal notation, for defining an object
in Javascript. From there we can declare Methods and member variables of that
object by specifying the name of the member, a colon and then the value that its
going to take. In this case we'd clear the method at the name draw String, we
use a colon and then we say that this is going to be a function, we use the
keyword function to define this and then we give a list of all the parameter.
And then open the function with an opening brace. Similarly to how you would in
many other languages. Now, again, we create a variable, name it, and then assign
to it, the value of gRenderEngine.context. Now this is going to take the
JavaScript object, gRenderEngine, and the dot notation is going to tell us that
we want the context member. Of this object and we do something similar down here
where we, grab the font member of the ctx object and assign it this felly here.
Now you notice that we're using additional strain. Addition is over loaded in
javascript to also designate strength encathnation Again similar to a lot of
other languages you might have seen. Next we have an example of an if statement.
If statements work essentially the same way that they would in any other
language where you have the keyword if, then in parenthesis you specify the
predicate that's going to return a bouillon value, either true or false and then
the body of the if statement that executes If that evaluates to true. Now, note
that the statement here doesn't have braces around it designating what executes
if the if statement evaluates to true. This is similar to some other languages
where, if there's a single line that you need to evaluate, you don't require
those braces. We use this here there. Just for readability purposes. So you
might see this in the code. Now for larger f blocks, you can delineate them with
a opening brace, and then once they are done, way down here, you close them with
another brace. From there we have a number more examples of declaring and
setting variables. And then we come to a fore loop. Fore loops are structured
essentially the way they are n c. The way we have An initializer value, then a
predicate to evaluate for when the for loop should end. And then an expression
to execute at the end of each for loop. And similarly, to you if blocks, the
block of code that you'd like to execute each time the for loop runs, is
delineated by braces. Although again, if it's a single line, you don't require
those braces to be there. There.
Now here we see words N where N is in square braces. And, again, N is the
variable that our for-loop is looping over. This is an example of accessing a
list, where N is the Nth element in that list. Now, like most other languages,
this is zero indexed as well. So keep that in mind.