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

Fix new usage in README examples #1

Merged
merged 1 commit into from Jul 15, 2012
Merged

Fix new usage in README examples #1

merged 1 commit into from Jul 15, 2012

Conversation

isaacs
Copy link
Contributor

@isaacs isaacs commented Jul 15, 2012

This:

x = new require('foo').Bar()
// is like:
x = (function () { var x = new require('foo'); return x.Bar()})()

What you really want is something like:

x = (function () { var x = require('foo').Bar; return new x()})()

so you need parens.

This works by accident, because new will return the ctor's
returned object if it's an object, and routes.Router doesn't
actually return an instance anyhow. However, if it ever did,
and it didn't use an instanceof check, then it would be a bug,
because it would poop on the global object.


    x = new require('foo').Bar()
    // is like:
    x = (function () { var x = new require('foo'); return x.Bar()})()

What you really want is something like:

    x = (function () { var x = require('foo').Bar; return new x()})()

so you need parens.

This works by accident, because `new` will return the ctor's
returned object if it's an object, and routes.Router doesn't
actually return an instance anyhow.  However, if it ever did,
and it didn't use an instanceof check, then it would be a bug,
because it would poop on the global object.
Raynos added a commit that referenced this pull request Jul 15, 2012
Fix `new` usage in README examples
@Raynos Raynos merged commit 8b41aad into Raynos:master Jul 15, 2012
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