What is the correct method to use if I want to alias DataManager.onLoad in multiple plugins?
If I use this for both of them:
var _DataManager_onLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad(object);
// do my stuff here
};
the method in the second plugin calls the method in the first plugin, which calls the original method. All three pass $dataActors as the object. But I get an undefined is not a function error on rpg_managers 141: this.extractMetadata(data);
If I give them different alias names:
var _DataManager_onLoad1 = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad1(object);
// do my stuff here
};
and
var _DataManager_onLoad2 = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad2(object);
// do my stuff here
};
I get the same results.
On the this.extractMetadata(data) line it's telling me this is Window, but it's not listing extractMetadata as an available function. When I disable both plugins and put a breakpoint on that line, it's telling me this is DataManager. So I can see the context/scope is being shifted somewhere.
If I pass in this as a first argument:
var _DataManager_onLoad1 = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad1(this, object);
// do my stuff here
};
and
var _DataManager_onLoad2 = DataManager.onLoad;
DataManager.onLoad = function(object) {
_DataManager_onLoad2(this, object);
// do my stuff here
};
the second plugin says this is DataManager and object is $dataActors, but when it gets through to the first plugin, it says this is Window and object is DataManager. It then passes DataManager through to the original function instead of $dataActors, so nothing gets processed.
It doesn't seem to matter whether I use the same variable name for the aliases or not.
The second function is calling the first function, and the first is calling the original, but I can't seem to get the right results, whether I include this as an argument or leave it out. What do I need to do so it passes through the correct arguments and knows that this is DataManager in each case?