mercredi 25 mai 2016

Javascript Facade method grouping

I'm working on a Facade class in Javascript. To make the class more manageable I would like to group related method in the facade. Consider my facade:

function Client(){this.a = 1;}

Client.prototype.methodA = function(){}
Client.prototype.methodB = function(){}

function SubClient = function(){}
Subclient.prototype.methodA = function(){}

I would like to be able to call method A in the sub client class like this using the context for the main Client:

var a = new Client() ;
a.SubClient.methodA() ;

I tried defining the subclient as an object but it doesn't use the same context. i.e. this.a is undefined

//Doesn't work - this.a is undefined
Client.prototype.SubClient = {methodA: function(){}}

Any ideas how this can be done or any suggestions. My facade class will be considerably big I would like to break it down.

Aucun commentaire:

Enregistrer un commentaire