Can javascript pass from inside the constructor

How can I go from this:

var abc = (function(){ 
  ..  
})();

register(abc); // outside the protected class

to this: (without calling the register outside the class):

function register(object){ stores the object }

var abc = (function(){
     ..       

     register(this); // inside the protected class
})();

Some background.

The master class has an array object of plugins, the "register" function places the plugin. abc will be such a plugin. plugins following module closure. I would like to put the plugin instances on the list, and the plugin will be as confident as possible. Additional features outside the plugin that I would like to remove.

I thought: MasterClass.plugins.abc = (function ..) but I think it creates a dependency on MasterClass.plugins to create an instance before loading any plugins.

+4
source share
1 answer

Function.prototype.bind() ( this) var , :

(function(){
var fun = function(){ alert( this.toString() )}
fun.bind(fun)();
})()

:

(function(){
var fun = function(){ alert( this.toString() )}
register(fun);
})()
0

Source: https://habr.com/ru/post/1543530/


All Articles