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

Already on GitHub? Sign in to your account

Fix `new` usage in README examples #1

Merged
merged 1 commit into from Jul 15, 2012

Conversation

Projects
None yet
2 participants
Contributor

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.

Fix `new` usage in README examples

    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

Merge pull request #1 from isaacs/patch-1
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