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

Two return statements in Mustache.getHelper #465

Merged
merged 1 commit into from Aug 30, 2013
Merged

Conversation

daffl
Copy link
Contributor

@daffl daffl commented Aug 30, 2013

Just curious as to why there are two return statements in the afore-mentioned function??

@daffl
Copy link
Contributor

daffl commented Aug 23, 2013

If you mean https://github.com/bitovi/canjs/blob/master/view/mustache/mustache.js#L1653, this is a common JS practise called early return. This avoids going through the whole loop because the function returns as soon as a matching helper has been found. I generally recommend using it. The easiest case looks like this:

function early(condition) {
    if(condition) {
        return 'true';
    }

    return 'false';
}

@daffl daffl closed this Aug 23, 2013
@djdev
Copy link
Author

djdev commented Aug 23, 2013

So, when will it go to the FOR loop.

And is it advisable to return NULL from a function.

On Fri, Aug 23, 2013 at 2:19 PM, David Luecke notifications@github.comwrote:

If you mean
https://github.com/bitovi/canjs/blob/master/view/mustache/mustache.js#L1653,
this is a common JS practise called early return. This avoids going through
the whole loop because the function returns as soon as a matching helper
has been found. I generally recommend using it. The easiest case looks like
this:

function early(condition) {
if(condition) {
return 'true';
}

return 'false';}


Reply to this email directly or view it on GitHubhttps://github.com//issues/465#issuecomment-23181642
.

@daffl
Copy link
Contributor

daffl commented Aug 23, 2013

Oh now I see what you mean! That looks pretty wrong ;)

@daffl daffl reopened this Aug 23, 2013
daffl added a commit that referenced this pull request Aug 30, 2013
Two return statements in Mustache.getHelper
@daffl daffl merged commit d567f29 into master Aug 30, 2013
@daffl daffl deleted the dead-mustache-code-465 branch August 30, 2013 21:07
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.

None yet

2 participants