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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access