I’m a bit confused as to where the line is for creating a new function for a task. For example, in “1.6.13 – VanillaPress V 0.3 – Toggling the Editor”, in the editor.init function you call a function (listenerEditorToggle). That function calls a helper function (getEditorToggleEl) which returns the editor toggle element and then adds the event listener, which calls the editor.toggle function to do the work.
When I wrote my version before watching the video, I replaced all of that with:
var elToggle = document.getElementById( ‘editorToggle’ );
elToggle.addEventListener( ‘click’, togglePanel, false );
in the editor.init function (our toggle functions were about the same).
I’m just curious of the rule of thumb for deciding, “Hey this needs to be a new function”. Since the getEditorToggleEl does nothing but call the native function getElementById, isn’t it redundant to wrap it in another function? Is this for future-proofing against element name changes or something? This pattern is being used in this project for any instance where you are using getElementById.
Thanks for a great course!