Two return statements in Mustache.getHelper #465

Merged
merged 1 commit into from Aug 30, 2013

Conversation

Projects
None yet
2 participants
@daffl
Contributor

daffl commented Aug 30, 2013

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

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Aug 23, 2013

Contributor

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';
}
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

This comment has been minimized.

Show comment
Hide comment
@djdev

djdev 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/bitovi/canjs/issues/465#issuecomment-23181642
.

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/bitovi/canjs/issues/465#issuecomment-23181642
.

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Aug 23, 2013

Contributor

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

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

Merge pull request #465 from bitovi/dead-mustache-code-465
Two return statements in Mustache.getHelper

@daffl daffl merged commit d567f29 into master Aug 30, 2013

1 check passed

default The Travis CI build passed
Details

@daffl daffl deleted the dead-mustache-code-465 branch Aug 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment