Why you should care
There should be no space between the name of a function and the ( (left parenthesis) of its parameter list, unless case of an anonymous literal function. If a function literal is anonymous, there should be one space between the word function and the ( (left parenthesis). If the space is omitted, then it can appear that the function’s name is function, which is an incorrect reading.Business Impacts
It is recommended to allow no spaces between the name of a function and the opening parenthesis of the list because more bugs in the portfolio and it prevents the code from being cost-effective.[nz_btn text="Cost" target="_self" animate="false" animation_type="ghost" color="green" size="small" shape="rounded" type="normal" hover_normal="opacity" hover_ghost="fill" link="http://casthighlight.wpengine.com/category/product/indicators-methodology/cost/" icon="icon-office"][nz_btn text="Time / Effort" target="_self" animate="false" animation_type="ghost" color="blue" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen" icon="icon-clock"]CAST Recommendations
CAST recommends having no space between function name and parenthesis. The JavaScript style guidelines by Douglas Crockford establish very consistent rules that help the code work well and perform with cost efficiency.References
https://stackoverflow.com/questions/9765942/space-after-function-name-is-wrong[nz_btn text="Style Guide" target="_self" animate="false" animation_type="ghost" color="turquoise" size="small" shape="rounded" type="ghost" hover_normal="fill" hover_ghost="screen" link="https://github.com/Kristories/awesome-guidelines" icon="icon-book"]How we detect
This code insight counts one violation each time a function declaration has no space between its name and the opening parenthesis and each time an anonymous function declaration has one or more spaces between the ‘function’ keyword and the opening parenthesis. function MyFunction (param) { // bad !!! // good (it’s a literal anonymous function: div.onclick = function (e) { return false; }; that = { // bad (it’s a literal function) method: function literal_fct (e) { return this.datum; }, datum: 0 }; }About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.
For reference only. For the complete details please refer the original article
https://doc.casthighlight.com/alt_prototype-spaces-between-function-name-and-opening-parenthesis-cause-bugs/
https://doc.casthighlight.com/alt_prototype-spaces-between-function-name-and-opening-parenthesis-cause-bugs/
Comments