I wanted to structure my javascript application with a modular pattern, as such:
APP = (function() {
// Private stuff
var _privateVariable = 'private',
_priv = 'priv'
_privateMethod = function(){ /* */ };
// Exposed API
return {
publicVariable : 'public',
publicMethod : function(){
return _privateVariable
};
}());
Then I want to be able to extend the application through plugin-like modules; for example, using jQuery:
$.extend(true, APP, (function() {
// Child private stuff
var _privateVariable = 'childPrivate',
// Exposed API
return {
}()))
What I am trying to achieve is either one of the following:
- When calling
APP.publicMethod()
after extending it, I want to return'childPrivate'
and not'private'
; - Be able to access
_priv
from the extended exposed API.
In summary, I would like that the private variables defined in the parent module would be inherited in the child module as private members of the child.