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-iamm
Posts: 133Questions: 55Answers: 2
in Editor
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
This discussion has been closed.
Answers
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
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