I'm fairly new to `node.js`, `prototypical inheritance` and the `CommonJS` module patterns.
Maybe this question was answered a million times, but I couldn't find it, so even a link to the answer is considered an answer.

I have to wrap a module that has both named and unnamed functions, like this:

```
// a.js
function a(data) {
    console.log(data, 'A')
}

function b() {
     a('B');
 }

module.exports = a;
module.exports.b = b;

```

Given OOP background I would like to somehow *'inherit'* all the functions of the module while I want to override the anonymous function (I'd like to add some fields to the data). 

**It is very important that after overriding `function a` in the new module `function b` should use the overridden method and not the original one.**

```
// 'inherited.js'
var a = require('./a');

function overriddenA(data) {
    data.myAddedValue = 'an important addition';
    a(data);
}    

// I would like to export all other functions and properties of the original module
[magic that overrides the anonymous function while keeping all other functions as they are]

```

From where I use it should look like this:

```
var decoratedA = require('./inherited');

decoratedA('stuff'); // it calls overridden function
decoratedA.b();      // it calls the original a.b() which in turn calls the overridden function

```

Solved our original problem
---------------------------

Check out this: <https://stackoverflow.com/a/31459267/2018771> - still if you have any comment on the abstract problem, please answer the question. We are curious :).