r/jquery • u/noodlylegs • Nov 03 '15
Unsuck my javascript
https://github.com/sleepyhead2gist/fullcalendar_bootstrap_tasklogger
This code uses FullCalendar and Bootstrap modal to log events into the calendar.
I am mostly a Photoshop/CSS person and would like to get better at JS.
This frankenstein-ish code that was cobbled together needs improvement and any input would be appreciated!
Some points that needs improvement in /test/source/javascript/custom.js
I've read that polluting global scope is bad. Some of my functions are in global scope Ex. validationCheck() . How can I include this function within the calendar scope?
My code has parts that are duplicated in 2 different functions. How can I consolidate duplicated parts so it can be used in different methods inside the calendar object?
I'm sure there are many others areas to improve so feel free to rip me a new one :)
2
u/[deleted] Nov 04 '15 edited Nov 04 '15
Break everything apart, it is SUPER rigid and difficult to read by defining all of your calendar options and vars inside the invocation. The only thing that needs to occur at docready is the calendar invocation, not calculating all of your values.
You should have zero variable definitions or method calls in there ( $( elem ) counts as a method call too )
You have inconsistent tab/space indentation.
You call functions synchronously before they are defined.