Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHANGE: Function Declaration examples #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stefanooldeman
Copy link
Contributor

No description provided.

@guidokessels
Copy link
Owner

var something = function() { ... }
is basically the same as
function something() { ...}

I think we should choose one format and stick to it.

I find this:

// Good
function outer() {

    var count = 10,
        name = "SpilGames",
        found = false,
        empty;

    function inner() {
        // code
    }

    // code that uses inner()
}

Much easier to read than this:

// Bad
function outer() {

    var count = 10,
        name = "SpilGames",
        found = false,
        empty,
        inner = function() {
            // code
        }

    // code that uses inner()
}

It adds extra indentation level and makes it harder to separate private function from private variables.

@stefanooldeman
Copy link
Contributor Author

The point is not the declaration of the variable, but the spacing in the function. JSLint says there should be a space between function and () and {.

The second thing is that these two should be both valid:

function init () {
    that.hasInit = true;
}

and

var init = function () {
   that.hasInit = true;
}

The fact that the styleguide says: only one var statement should be used per scope, does not mean that the function body has to resided on the same line as the variable declaration (although this is done in all our modules currently and has always been a convention).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants