1. The functions provide() and require() of Dojo toolkit and Google’s Closure library are used for
a) declaring and loading modules
b) loading and declaring modules
c) declaring modules
d) none of the mentioned
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: 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) All of the mentioned
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) The function’s scope
b) Module function
c) Modulated 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: 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) Store the module’s API and register their API
c) Store the module’s API
d) None of the mentioned
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. Consider the following code snippet
var sets = com.davidflanagan.collections.sets;
What is the programmer trying to do in the above code snippet?
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) None of the mentioned
Explanation: The 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).