elgrancalavera/grunt-extend — pull request #2 by nathanprobst (2013-09-23 21:37:42+00:00)
Title: Allow extension of JS modules in addition to JSON objects.

This is useful (to me) for building a layered configuration modules incorporating both primitives and functions.

Here's an example to illustrate...

#### base-config.js
```js
module.exports = (function() {
var self = {
company: {
name: 'DEFAULT'
},
copyright: {
year: '2011',
message: function () {
return 'Copyright ' + self.copyright.year + ' by ' + self.company.name + '. All rights reserved.';
}
}
}
return self;
})();
```

#### override-config.js
```js
module.exports = (function() {
var self = {
company: {
name: 'SomeCo'
},
copyright: {
year: '2013'
}
}
return self;
})();
```

#### Gruntfile.js
```js
grunt.initConfig({
extend: {
options: {
require: true
},
extendedConfig: {
files: {
'resulting-config.js': ['base-config.js,', 'override-config.js']
}
}
}
});
```

#### resulting-config.js
```js
module.exports = (function() {
var self = {
company: {
name: 'SomeCo'
},
copyright: {
year: '2013',
message: function () {
return 'Copyright ' + self.copyright.year + ' by ' + self.company.name + '. All rights reserved.';
}
}
}
return self;
})();
```

#### app.js
```js
require('resulting-config.js').copyright.message(); // Copyright 2013 by SomeCo. All rights reserved.
```