Is there a reason not to use "this" in an editor event?

Is there a reason not to use "this" in an editor event?

washuit-iammwashuit-iamm Posts: 50Questions: 22Answers: 1

Example: editor.on('initEdit', function(a, b, c){ var myEditor = this; });

I did not see any examples showing this. I am currently using the above in many places to get an editor instance inside my event.

Is that okay?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 3,983Questions: 0Answers: 704
    Answer ✓

    Hi @washuit-iamm ,

    No, there's no reason why you can't - in the examples, since the editor object was used to create the event handler, for simplicity it made sense to use it again. This example here is using your way on the "make empty" functionality.

    Cheers,

    Colin

  • allanallan Posts: 49,056Questions: 1Answers: 7,171 Site admin

    Yup - as Colin says, that is 100% valid. The Editor events are executed with a scope of the Editor instance so this will indeed be the Editor instance in the event handler function.

    I'm not sure why I've got into the habit of using the editor variable inside the event handlers! Probably just for clarify as to what is being acted on.

    Allan

Sign In or Register to comment.