https://github.com/naugtur/extendable-module
Extendable Revealing Module - lets you extend the private parts [ seriously ;) ]
https://github.com/naugtur/extendable-module
Last synced: 4 months ago
JSON representation
Extendable Revealing Module - lets you extend the private parts [ seriously ;) ]
- Host: GitHub
- URL: https://github.com/naugtur/extendable-module
- Owner: naugtur
- Created: 2012-07-08T08:55:02.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-08-08T19:35:08.000Z (about 13 years ago)
- Last Synced: 2025-02-15T07:42:15.371Z (8 months ago)
- Language: JavaScript
- Size: 93.8 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Extendable Revealing Module
===========## This was a fun experiment, but I don't recommend using it. It introduces funny problems with scope.
JavaScript's popular Revealing Module pattern has this disadvantage that it is impossible to extend any behaviour related to the private parts [this joke is never getting old].
This little bit of code has been devised to do just that.
## Usage:
`Module.extend` - pass a callback function that does the extension. The callback gains access to the whole module definition (passed as the single argument).
`_public` - a private array of properties that are supposed to be publicly avaliable.
### Example:
var Duck = Module.extend(function(M) {
// M is the private parts
M.sound = 'Quack';M.translateToDucky = function(a) {
return a.split(' ').join(' '+M.sound+' ');
}//set up what will be public
M._public.push('say');
M.say = function(a) {
return M.translateToDucky(a);
}//just remember to do this
return M;});
Duck.say('Hello all you happy people');
//Hello Quack all Quack you Quack happy Quack people## Files
`module.js` - basic Extendable Revealing Module implementation.
`module.amd.js` - AMD-enabled Extendable Revealing Module implementation.
`test.js` - longer example