HTML and CSS Reference
In-Depth Information
this.observable = Object.create(tddjs.util.observable);
},
/* ... */
});
TestCase("ObservableNotifyObserversTest", {
setUp: function () {
this.observable = Object.create(tddjs.util.observable);
},
/* ... */
});
To avoid duplicating the Object.create call, each test case gained a setUp
method that sets up the observable for testing. The test methods have to be updated
accordingly, replacing observable with this.observable .
For the tests to run smoothly on any browser, the Object.create imple-
mentation from Chapter 7, Objects and Prototypal Inheritance, needs to be saved in
lib/object.js .
11.6.3 Renaming Methods
While we are in the game of changing things we will take a moment to reduce the ver-
bosity of the interface by renaming the addObserver and notifyObservers
methods. We can shorten them down without sacrificing any clarity. Renaming
the methods is a simple case of search-replace so we won't dwell on it too long.
Listing 11.41 shows the updated interface, I'll trust you to update the test case
accordingly.
Listing 11.41 The refurbished observable interface
(function () {
function observe(observer) {
/* ... */
}
/* ... */
function notify() {
/* ... */
}
tddjs.namespace("util").observable = {
 
Search WWH ::




Custom Search