-
Book Overview & Buying
-
Table Of Contents
Getting Started with hapi.js
By :
In hapi, the goal is never to monkey-patch or modify any of the normal Node objects or methods, but only to provide an extra layer around them to access the important parts.
Monkey patching is the method of overriding or extending the behavior of a method. For example, let's create an add function that returns the sum of two numbers:
let add = function (a, b) {
return a + b;
}We now want to log in to the console every time this is called, without altering the existing behavior. We would modify it by doing the following:
let oldAdd = add;
add = function (a, b) {
console.log('add was called…');
return oldAdd(a, b);
}Now every time add is called, it will print add was called…, and return the sum just as before. This can be useful in modifying core language methods, but is not a recommended pattern, as it can cause very hard-to-debug side effects. I generally limit doing this to writing tests or debugging code.
This is the case with the...
Change the font size
Change margin width
Change background colour