Sharing state between multiple functions on the prototype

48 Views Asked by At

I am creating a client side remote object in Eclipse RAP using Javascript for a text widget. I am then adding functions to the object's prototype in order to be handle various events and to do other business logic. Now some of these functions need access to the text widget.

Assuming that init() is always the first function invoked. I am wondering if it would be a good idea to store the text widget on the TextObject's prototype? Are there any better ways to achieve this?

Edit: Another thought I had was to pass the text widget to every function which needs it but I don't like that either.

function TextObject() { }

TextObject.prototype = {

   widget:null,

   init: function(text)
   {
      this.widget = text;
   },

    incrementNumber:function() 
    {
       if(this.widget!=null)
       let textString = this.widget.getText();
    }
};
0

There are 0 best solutions below