0

hi I have a Question about accessing variables that are in a parent function

var DateRangePicker = function (name, clickFunction) {
    this.context = name;
    this.UpdateGraph = clickFunction;
    this.FinalDate = function () {
        var Dates = $(this.context).find("[name=datepickerText]").val().split('-');
        return Dates[1];
    };
    this.InitialDate = function () {
        var Dates = $(this.context).find("[name=datepickerText]").val().split('-   ');
       return Dates[0];
    };
    $(this.context).find("[name=UpdateDatepicker]").click(function () {
        var pickerText = $(InnerContext).find('[name=datepickerText]');
        var dates = pickerText.val().split('-');
        UpdateGraph(InitialDate(), FinalDate());
        $(context).find("[name=Toogler]").click();
    });
    return this;
}

How can i access the "this.UpdateGraph()" function inside the updateDatepicker click so far it sais that UpdateGraph and this.UpdateGraph doesnt exists

1
  • 1
    define var self = this in parent function and use self.UpdateGraph in child function Commented Jun 29, 2016 at 19:16

1 Answer 1

1

You can bind the this context to your handler function, to keep from having an extra scope variable:

$(this.context).find("[name=UpdateDatepicker]").click(function () {
    var pickerText = $(this.InnerContext).find('[name=datepickerText]');
    var dates = pickerText.val().split('-');
    this.UpdateGraph(this.InitialDate(), this.FinalDate());
    $(this.context).find("[name=Toogler]").click();
}.bind(this));
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad it helped. Make sure to mark an answer as accepted when you find the one that best addresses your question, so people searching know which answer worked.

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.