Hi,
Not sure if this is possible, but I have an external script that creates an object, and I want to overwrite some of its functionality, but keep the scope.
Here is a basic example:
<script>
Obj = function (userConfig) {
this._init(userConfig);
};
Obj.prototype = {
_init: function () {
console.log(this);
}
};
var oldInit = Obj.prototype._init;
var newInit = function() {
console.log(this);
}
Obj.prototype._init = function() {
oldInit();
newInit();
}
var testObj = new Obj();
</script>
I want it to log two Objects, but instead I get two window elements. Is this because I am declaring the functions in the global scope, and not from within the object?
Anyway I can keep the scope of the object, whilst still overwriting the function?
Cheers!