Search code examples
javascripteventsclickgoogle-closuregoogle-closure-library

Passing argument with goog.events.listen


I'm using Google Closure's event handling like this:

goog.events.listen(this.contentElement, goog.events.EventType.CLICK, this.openEditor);

But I need to pass a string as an argument into the function which would be this.openeditor

I've looked through the documentation but can't seem to work out how to do this, anyone got any ideas?

Thanks!


Solution

  • Try using goog.partial, like this:

    goog.events.listen(this.contentElement, goog.events.EventType.CLICK, goog.partial(this.openEditor,'the string you want to pass it'));
    

    When this.contentElement is clicked, this.openEditor will be called. The fist parameter will be the string and the second parameter will be an event object.