I wrote a small jQuery application recently to practise the language and got some feedback which criticised it in the following:
- you don’t use any message passing in your functions,
- you had hard coded values for some of your data (eg: the colours),
- you had initalisation code embedded rather than extracted out into a separate JSON file
But I dont really understand what they mean, and how I remove these issues.
Can anyone give me rough examples of them, and the correct approach?
Thanks for any help!
Probably he suggested that you are only using global variables, and no functions with parameters. That can be a choice, but I’d say it doesn’t matter in smaller web applications.
Hardcoded static data can be irritating when you want to change it. If you decide that the color must me more bluish than it is now, you have to find and replace every single place where you used that color. Using a variable for that color, you only have to change something once, and you avoid hard-to-find bugs
Also practical reasons. Instead of editing the entire JavaScript file, you only have to change the small init file. This can be handy for testing purposes, or in big projects.