Learn MORE JavaScript on the ServiceNow Platform: Lesson 7 Exercise - The practice of NameSpacing
Okay. Exercise time. I want you to create a namespace
for a mock ServiceNow application. The namespace should include
a version property, an initialization function,
and a sub namespace. For utilities
with a couple of utility functions. You can name them whatever you want,
but I want them to be in a sub namespace within your namespace. Demonstrate
calling one of these utility functions from that namespace
and let's see how it goes. Go ahead and pause right now
and we'll see you on the other side. Okay, so here's what I came up with. Here's my ServiceNow app namespace. It has a version 1.0 init function. And when you when it's called,
it just says the version number and then it has a subtheme space of utils
which has a log one and it has a calculation
of calculating a couple of numbers. just including that one for fun.
All right. Let's go ahead and take this and load it into ServiceNow, see how it runs. You'll see that I'm calling
that initialization function. And then I'm calling the sub namespace
with its own method inside of it. And there you go. It initialized showed the version number and said, Hello, ServiceNow from the log. Nested sub spaces. It's going to be a lot of fun. How did your’s turn out? Tell me more about yours or copy
and paste directly into the comments so we can see what
your namespaces look like.
https://www.youtube.com/watch?v=9eZjA8qwuVc