Skip to content

A very minimal JS code for teaching about closures

License

Notifications You must be signed in to change notification settings

napunapu/closuredemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

closuredemo

A very minimal JS code for teaching about closures

Software needed

Node.js from http://nodejs.org/ or installed by your favourite package manager.

Usage

node server.js

Fetch the file with a browser: http://localhost:3000/demo.html

Teaching

File: demo.html

The point is to show how the req variable is usable even if it is executed only after the network request returns.

To stress the point it may be handy to make the server code slower with e.g. setTimeout function. (Which incidentally can teach more about closures.)

Another demonstration is to make the req object null after the req.send(null) function call.

About

A very minimal JS code for teaching about closures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published