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

Code example "isThisCool" in Ch3 "Types and Grammar", "Native Prototypes" throws error #1366

Open
komali2 opened this issue Oct 23, 2018 · 1 comment

Comments

@komali2
Copy link

@komali2 komali2 commented Oct 23, 2018

Link: https://github.com/getify/You-Dont-Know-JS/blob/master/types%20%26%20grammar/ch3.md#native-prototypes

The code example is as follows:

function isThisCool(vals, fn, rx) {
    vals = vals || Array.prototype;
    fn = fn || Function.prototype;
    rx = rx || RegExp.prototype;

    return rx.test(
        vals.map(fn).join("")
    );
}

isThisCool();		// true

isThisCool(
    ["a", "b", "c"],
    function (v) { return v.toUpperCase(); },
    /D/
);

In node (latest version) and chrome (latest version), I get this error from the above code:

    return rx.test(
              ^

TypeError: Method RegExp.prototype.exec called on incompatible receiver [object Object]
    at Object.exec (<anonymous>)
    at Object.test (<anonymous>)
    at isThisCool (/home/calebjay/Documents/personal/test.js:6:15)
    at Object.<anonymous> (/home/calebjay/Documents/personal/test.js:11:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.