SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 108 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

.in loop.
You can add additional properties onto your object at any time by using dot or bracket
notation:
customObject.value = 6;
customObject["otherValue"] = 7;
customObject.newMethod = function(){};
CHAPTER 3 n OBJECT-ORIENTED PROGRAMMING 63
The object literal is limited in that you can??™t use it as a class to instantiate new objects.
One object is defined, and that??™s it. Having only one of an object can be a very good thing.
Sometimes you want only a central location to manage things (this is often referred to as a
singleton design pattern).
nNote Design patterns are recurring approaches to a problem. By understanding the various approaches
to solving a problem, you can choose the solution that best fits a problem you might be having. Read more
about design patterns in Wikipedia at http://en.wikipedia.org/wiki/Design_pattern_
(computer_science).
The ElementReady object defined in the last chapter is a great example. Here??™s a snippet of
that object:
var ElementReady={
polled:[], /* store polled elements */
timer:null, /* store timer */
timerStarted: false,
ceasePoll:function()
{
clearTimeout(this.timer);
this.timerStarted = false;
},
startPoll:function()
{
if(!this.timerStarted) this.timer = ~CCC
setTimeout(function(){ElementReady.check(false)},100);
}
}
The object literal made sense as a central point of access to control the execution of all
functions with just one timer.


Pages:
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
druga wojna światowa Free English grammar and study guid hotel jelenia góra Russian bride counter strike 1.6