Yes, they meant that if they wanted to make a compatibility plugin between two other plugins, they may need to call the older method of one of them. When you alias a method to a simple var inside the anonymous function, that var can't be accessed from anywhere else.
But there's nothing wrong with anonymous functions, in fact, it's bad NOT to use them. The problem estriole mentioned lies with using something inside it and not exporting it to be accessed outside.
I don't bother exporting my aliased methods because I can make compatibility patches myself.
because everything inside that anonymous function is scopped to that function, including aliases. This is great if you are creating classes, functions, varaibles and so on that cannot be mutated randomly by people trampeling all over the code base.
I use this concept in the form of modules. In ES6 for example when you export something or import something, when compiled down it wraps the code in these types of functions.
Shouldn't plugins be like black boxes?
Is this ONLY an issue when you're trying to make a compatibility patch between two?
Can anyone give an example of two plugins - actual code (hypothetical is fine) where this would become a problem, and an example of how they could be written to overcome the problem?
I'm just trying to determine whether I should go back and redo all of mine.
two plugin who alias the same update
// original methodSpriteset_Base.prototype.initialize = function() { Sprite.prototype.initialize.call(this); this.setFrame(0, 0, Graphics.width, Graphics.height); this._tone = [0, 0, 0, 0]; this.opaque = true; this.createLowerLayer(); this.createToneChanger(); this.createUpperLayer(); this.update();};// method A called beforevar alias_A = Spriteset_Base.prototype.initialize;Spriteset_Base.prototype.initialize = function() {alias_A.call(this);//your content};// method B called aftervar alias_B = Spriteset_Base.prototype.intialize;Spriteset_Base.prototype.initialize = function() {//your contentalias_B.call(this);};you may encounter bug with the update method.
SINCE if you do method A they will call update BEFORE material is created.
SO if example I do method A...it's just create something new and don't update without a flag. then it's fine
BUT method B require to always update. then it's will be fine to call it.
Now here begin the problem if we input the plugin.
If method A is call before Method B it's will provoke a crash of no method since ...update is call BEFORE method b is call. so this why Anonymous don't help here since we can't reach the other method alias for do this :
var alias_A = alias_B.prototypeSpriteset_Base.prototype.initialize = function() {alias_A.call(this);//your content};where it's will get the content of B and not provoking bug. Although not the best performance method
EDIT :
the problem with alias in general are they are hierarchical and depends of the specific order you call them. The way's to fix this would be the way's you organize your plugin order so method_B would not get a error since it's alias is call before method A so it's have time to get call.
You should declare "Milena" outside the function, otherwise it won't be accessible by other plugins or the user.
Ha... thanks, now I understand. <3
Just so I can understand this a bit better.
For example, with aliasing and creating our black box plugins.
So for example as Zalerinian mentioned.
They store the old aliases in a js object.
Example:
//Maintain global scopevar module = { //list of aliases to be used. }(function(){ //references to functions from the module //my code here })();We should be doing something like the above?
Also, would it be a good idea to reference our anonymous function as it's own module if we wanted other users to have access to it?
Example:
var myPlugin = (function(){//plugin code})();Or is this a bad idea?