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: 133Questions: 55Answers: 2

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: 15,240Questions: 1Answers: 2,599
    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: 63,498Questions: 1Answers: 10,471 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

This discussion has been closed.