0

I have already read this post : JSLint, else and Expected exactly one space between '}' and 'else' error and it didn't help me to know the reason of this rule.

EDIT : I see that my question is set to duplicated, but I have mention the first line that I came from this post and I could not find the answer until the other post talk about the return line before a { when My question ask for the space between ) and {. SO I don't see a reason for duplicated. Thanks

I always use to write my function / statement, without any space. Like this :

This is wrong for JSLint :

var myFn = function(data){

}

if(true){

}else{

}

This is correct for JSLint :

var myFn = function (data) {

}

if (true) {

} else {

}

This lead me through the error. But for which reason it is better to add a space between the function and the (? And between the ) {?

I see that like a waste of time to add all this space every time. Why this decision?

EDIT On http://www.jslint.com/help.html , we can read "The word function is always followed with one space.

Spaces are used to make things that are not invocations look less like invocations."

So that is kind of answer I was looking for.

I don't know if I am ready for this... :D

Community
  • 1
  • 1
Ganbin
  • 2,004
  • 2
  • 12
  • 19
  • 5
    One word: readability – Matteo Tassinari Feb 15 '16 at 15:32
  • Just remember that JSLint is a tool written for Douglas Crockford and others can find more or less useful :) – Álvaro González Feb 15 '16 at 15:35
  • 2
    You said your read it but did you actually _read_ it? – Jeff Mercado Feb 15 '16 at 15:37
  • Thanks for comments, I know that's is a Douglas Crockford preference. But he say that he didn't choose a rule based on his personal preferences but based on the efficiency of the code. So I wish to get an technical answer. – Ganbin Feb 15 '16 at 15:39
  • @MatteoTassinari Thanks, but if you read the first line of my post I already say that I cannot find the answer I want in this post. The post talk more about the effect to put an return line before the else statement and not about the space between the curly bracket. – Ganbin Feb 15 '16 at 15:40
  • Ok I will listen all the talk of him and maybe he talk already about it. :D – Ganbin Feb 15 '16 at 15:42
  • Notice, that [Crockford's code convention](http://javascript.crockford.com/code.html) recommendations are originally written for simple editors without code coloring etc. Also there might have been lousy interpreters reading an anonymous function as a call of `function` without that space. – Teemu Feb 15 '16 at 15:44
  • On http://www.jslint.com/help.html , I can find this quote that help me to understand this choice : "The word function is always followed with one space. Spaces are used to make things that are not invocations look less like invocations." – Ganbin Feb 15 '16 at 15:58

0 Answers0