You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

logic.js: Passing constructor references to event handler

Received Response
7
Views
6
Comments
edited Jun 4, 2018 8:24AM in Customer Portal 6 comments

Content

I have the following code that I'm trying to use:

 

Custom.Widgets.test.foo = RightNow.Widgets.extend({
    constructor: function() {
        this._textElement = this.Y.one(this.baseSelector); 
        if (this._textElement)
        {            
            this._textElement.on("change", this._onChange, this);
        }
    },    
    _onChange: function(evt)
    {
        var textBoxValue = this._textElement.value; // throws undefined error
		
		// how do I access the text textbox value here without using a global variable
    }    
});

 

I understand that inside "_onChange", the scope of "this" changes. But is there a way I can maintain the constructor's scope too inside the event handler?

PS: I'm aware of the alternative of using a global variable and then assigning it to "

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!