1. The functions provide() and require() of Dojo toolkit and Google’s Closure library are used for
a) declaring and loading modules
b) declaring functions
c) declaring modules
d) loading modules
Explanation: Both the Dojo toolkit and Google’s Closure library define provide() and require() functions for declaring and loading modules.
2. The maximum number of global symbols a module can define is ____________
Explanation: Generally, the various modules are allowed to run in the pristine (or near pristine) environment that it expects. The modules should minimize the number of global symbols they define – ideally, no module should define more than one.
3. To define each of the set classes as a property of the sets object (namespace) for the module, the statement is
a) sets = sets.AbstractEnumerableSet.extend(); b) sets.SingletonSet = sets.AbstractEnumerableSet.extend(...); c) sets.SingletonSet = sets.extend(...); d) sets = sets.extend(...);
Explanation: Singleton is an object which can only be instantiated once.The extend keyword is used in class declarations or class expressions to create a class which is a child of another class. The sets object is the namespace for the module, and we define each of the set classes as a property of this object.
4. Consider the following statement
var Set = sets.Set; var s = new Set(1,2,3);
What could be the efficiency quotient of the above two statements ?
a) The programmer imports at once the frequently used values into the global namespace
b) There is no efficiency quotient, the programmer tries to make it inefficient
c) The programmer needs to import the Sets everytime he wants to use it
d) the programmer imports the set everytime the statement is encountered
Explanation: A programmer can import frequently used values into the global namespace. A programmer who was going to make frequent use of the Set class from the sets namespace might import the class like that.
5. The scope of a function is also called as ________
a) Predefined function
b) Module function
c) Public function
d) Private function
Explanation: The scope of a function can be used as a private namespace for a module. Therefore, the scope of a function is called a module function.
6. Modules that have more than one item in their API can ________
a) Assign itself to a global variable
b) Invoke another module of the same kind
c) Return a namespace object
d) Invoke another module of the same kind
Explanation: Namespace is a container for set of identifiers, functions, methods and all that. It gives a level of direction to its contents so that it will be well distinguished and organized. Modules that have more than one item in their API can return a namespace object.
7. The provides() function and the exportsobject are used to _________
a) Register the module’s API and Store their API
b) Call the modules api
c) Store the module’s API
d) Register the modules api
Explanation: Frameworks that define module loading systems may have other methods of exporting a module’s API. There may be a provides() function for modules to register their API, or an exports object into which modules must store their API.
8. What could be achieved by running the code snippet below?
var sets = com.davidflanagan.collections.sets;
a) Importing a single module
b) Importing a module partially
c) Importing a namespace
d) Importing the entire module
Explanation: Rather than importing individual classes, a programmer might import the entire module to the global namespace.
9. The properties() method is a ________
a) Enumerable method
b) Non-enumerable method
c) Operational method
d) calling method
Explanation: The properties() is a method to get information of the properties of a particular object. properties() method is a non-enumerable method.
a) To use a method that defines all the variables
b) To use an object that has the reference to all the variables
c) To use an object as its namespace
d) To use global functions
Explanation: One way for a module to avoid the creation of global variables is to use an object as its namespace. Instead of defining global functions and variables, it stores the functions and values as properties of an object (which may be referenced to a global variable).