HTML and CSS Reference
Building a custom object library
In this thought experiment, apply what you've learned about this objective. You can
find answers to these questions in the “Answers” section at the end of this chapter.
You need to create multiple websites that all leverage the same backend database.
You will use AJAX to make server requests for data. You want to create a custom
library that can be used among the various websites. You are concerned about
naming objects because you know that many other libraries are integrated with the
How can you design your library so that it doesn't conflict with other libraries in
■ Variables are undefined until they are initialized.
■ Variables are scoped and accessible depending on where they are declared. If they are
inside a function, for example, they are local to the function.
■ Passing parameters is the only way to make a local variable available in another
■ The global namespace shouldn't be used because it's shared by all.
■ You should apply a namespace to custom objects to prevent conflicts in the global
■ The this keyword provides direct access to the object that raised the event.
Answer the following questions to test your knowledge of the information in this objective.
You can find the answers to these questions and explanations of why each answer choice is
correct or incorrect in the “Answers” section at the end of this chapter.
The scope of a variable is global within the context of the page.
The scope of a variable depends on where inside the script it's declared.
The scope of a variable changes depending on the type it represents.