1

Even though there are similar questions, I couldn't find the solution of this case. In javascript, I have two ui widgets (let's call textbox1 and textbox2). My purpose is to write a generic handler for those functionalities. For example instead of doing following code,

initialize: function(element, options){

    if(options.isTextbox1){
       return element.textbox1(options);
    }
    return element.textbox2(options);

}

I would like to do as following,

var mode;
initialize: function(element, options){
    if(element.isTextbox1){
        mode = element.textbox1;
    }
    else{
        mode = element.textbox2;
    }
    return mode(options);
}

However, the second code piece is throwing exception as

Uncaught TypeError: this.each is not a function

thrown from jquery-ui-1.9.2.

What would be the appopriate way to handle this situation?

1 Answer 1

1

I was able to solve it.

Here is the usage

var mode;
initialize: function(element, options){
    if(element.isTextbox1){
        mode = 'textbox1';
    }
    else{
        mode = 'textbox2';
    }
    return element[mode](options);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.