As for a JS-newbie, I'm struggling with JS-closure. Googled enough, though can't understand why "this" is not available in "store" function. Any help will be appreciated:
;(function (win) {
var _af = function(storeObjectName, storeObjectValue) {
var self;
if (_af.prototype.instance) {
self = _af.prototype.instance;
} else {
self = Object.create(_af.prototype);
_af.prototype.instance = self;
self._init();
}
if (arguments.length == 1) return self.fire(storeObjectName);
if (arguments.length == 2) self.store(storeObjectName, storeObjectValue);
return self;
};
_af.prototype = {
afVariable: '_af',
afObject: {},
_init : function(){
this.afObject = this.get(self.afVariable);
},
store : (storeObjectName, storeObjectValue)=>{
// This throws the error, that this.get is not defined
this.get('_af');
},
get : storageObject=>{
if (!storageObject)
this.afObject = '_af';
else
this.afObject = '_someother'
}
}
win._af = _af;
}(window));