Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Module Pattern in JavaScript

Followed examples don't work for me

When I'm trying to implement what Huston has written:

    !function(underscore){
    underscore.someawesomemethod = "Really cool";
    console.log(underscore.VERSION);
}(_);

I've got an error that tells me: "Uncaught ReferenceError: _ is not defined"

What do I do wrong?

4 Answers

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

make sure that you have the underscore library linked in your html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Test</title>
</head>
<body>

<!-- underscore linked below -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>

!function(underscore){
    underscore.someawesomemethod = "Really cool";
    console.log(underscore.VERSION);
}(_);

</script>
</body>
</html>

Oh I really missed it. Thank you

Michael Kellogg
Michael Kellogg
774 Points

Would be good if in the video he would show doing this. Otherwise it just magically shows up and people following along have no idea.

This video is a trainwreck. He references libraries and things that have never been talked about before on the "full stack javascript" track. This needs to be split up into a few courses. It feels way too rushed.

I just watched this....and yes, I feel the exact same way.

I've got in linked in index and still having the uncaught ref error issues for (_)

Worked perfect. Thanks