Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MEAN Web Development

You're reading from   MEAN Web Development Master real-time MEAN web application development and learn how to construct a MEAN application using a combination of MongoDB, Express, AngularJS, and Node.js

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher Packt
ISBN-13 9781783983285
Length 354 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Amos Q. Haviv Amos Q. Haviv
Author Profile Icon Amos Q. Haviv
Amos Q. Haviv
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Introduction to MEAN 2. Getting Started with Node.js FREE CHAPTER 3. Building an Express Web Application 4. Introduction to MongoDB 5. Introduction to Mongoose 6. Managing User Authentication Using Passport 7. Introduction to AngularJS 8. Creating a MEAN CRUD Module 9. Adding Real-time Functionality Using Socket.io 10. Testing MEAN Applications 11. Automating and Debugging MEAN Applications Index

JavaScript closures

Closures are functions that refer to variables from their parent environment. Using the closure pattern enables variables from the parent() function to remain bound to the closure. Let's take a look at the following example:

function parent() {
    var message = "Hello World";

    function child() {
        alert (message);
    }

    child();
}

parent();

In the preceding example, you can see how the child() function has access to a variable defined in the parent() function. But this is a simple example, so let's see a more interesting one:

function parent() {
   var message = 'Hello World';
    
  function child() {
    alert (message);
   }

   return child;
}

var childFN = parent()
childFN();

This time, the parent() function returned the child() function, and the child() function is called after the parent() function has already been executed. This is counterintuitive to some developers because usually the parent() function's local...

You have been reading a chapter from
MEAN Web Development
Published in: Sep 2014
Publisher: Packt
ISBN-13: 9781783983285
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime