2

I have this code in component helper:

func1:function (component){
    var element = component.find("calendar").getElement();
    $(element).fullCalendar({
        views: {
            year: { // name of view
                columnFormat: 'MMM'
                // other view-specific options here
            }
        },
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'year,month,basicWeek,basicDay'
        },
        events: data,
        viewRender: function(view){
            console.log("**** "+view.name);
            this.func2(component);
        }
    )}
},
func2:function(component){
    .
    .
}

but it display an error indicate that func2 is not defined so how can I call helper function from inner functions?

1 Answer 1

4

You need a reference outside the inner function to this:

// in outer function
var self = this;

...

self.func2(component);

When a method is called, "this" is typically set to the object that called the function. Sometimes it's hard to tell what "this" even is. Most likely, "this" inside your particular function refers to the FullCalendar module, or perhaps jQuery, but most certainly doesn't refer to the helper object.

As an alternative, you can use arrow functions, but be aware that IE does not support them (but Edge does).

viewRender: (view) => { this.func2(component); }
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .