jsmoo
Version:
JavaScript Minimalist Object Orientation
41 lines (36 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
// The after function importe to the global import of JSMOO
//
// object = The Ojbet on which the after funcition will search for the method to attach
// method = A string with the name of the method to attach
// func = The function which will be called after the method
function after(object, method, func) {
if (object.prototype) {
//TODO: FOR STATIC METHODS
//const oldFunction = object[method];
//object[method] = (...args) => {
//oldFunction.bind(object)(...args);
//afterFunction.bind(object)(...args);
//};
} else {
if (!object._afterFunctions_) object._afterFunctions_ = [];
object._afterFunctions_.push({ method: method, func: func });
}
}
// Function exported to the Jsmoo.js to attach the after functions to the new object
function defineAfterFunctions() {
var _this = this;
if (!this._afterFunctions_) return;
this._afterFunctions_.forEach(function (override) {
var oldFunction = _this[override.method];
_this[override.method] = function () {
oldFunction.bind(_this).apply(undefined, arguments);
return override.func.bind(_this).apply(undefined, arguments);
};
});
}
exports.default = after;
exports.defineAfterFunctions = defineAfterFunctions;