O'Reilly logo

Quality Code: Software Testing Principles, Practices, and Patterns by Stephen Vance

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Temporarily Replace

Some languages provide another way to test what code does without invoking the things that it calls. In the previous section, we showed a technique for locally redefining a function for the duration of the block, but the method will be redefined for all instances created from the module around the redefined function if you are using modules in an object-oriented way.

In contrast, JavaScript, with its dynamic characteristics and prototypal inheritance, allows each instance of an object to be independently customized. You can create an instance of an object and replace the implementation of its methods without modifying the behavior of the methods in any other instance (Listing 6-10).

Listing 6-10: Simple example of replacing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required