In this widget there is a function isPermitted()
. How would I intercept it and overwrite it.
I use the following to intercept other functions isPermittedDomain
etc, but unable to overwrite the isPermitted
function. Any suggestions?
this is the function I'm trying to intercept and overwrite:
n.prototype.isPermitted = function (t) {var n = !this.direct || 'OW2017' !== e.AppSettings.omo_username;
return !n && t && this.onFail(new e.ErrorMessage({ error: 'FEED_NOT_PERMITTED' })), n;
};
My code:
function intercept(obj, prop, callback) {
var oldVal = null;
Object.defineProperty(
obj, prop, {
get: function() {
return oldVal;
},
set: function(newVal) {
callback.call(this, newVal);
oldVal = newVal;
},
enumerable: true,
configurable: true
});
};
intercept(Opta, 'Subscriptions', function(Subscriptions) {
Subscriptions.isPermittedDomain = function() {
return true;
};
intercept(Subscriptions, 'feeds', function(feeds) {
const t = Opta.Trans.loadTerms({
term_set_id: Opta.Trans.mapSportIdToTerms(1)
});
Opta.when(t).done(startReact);
});
});
How about an approach which straightforwardly provides interception handling by wrapping the intercepting handler around the original (prototypal)
isPermitted
method. And for convenience reasons (code-reuse of the wrapping pattern) one would make use of an immediately invoked arrow function expression.