Skip to content

Commit 60c5bd3

Browse files
committed
Updated code
1 parent 465d0bd commit 60c5bd3

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

Closures/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Closures
2+
3+
Closures are functions that refer to independent (free) variables (variables that are used locally, but defined in an
4+
enclosing scope). In other words, these functions 'remember' the environment in which they were created.

Closures/main.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// With closures, we can access variables that would otherwise be out of scope
2+
3+
function Person(pName){
4+
var name = pName;
5+
6+
this.getName = function () {
7+
return name;
8+
}
9+
}
10+
11+
var bucky = new Person("Bucky Roberts");
12+
13+
console.log(bucky.name); // undefined (out of scope)
14+
console.log(bucky.getName()); // Bucky Roberts

_template/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Title
2+
3+
Description

_template/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* Created by Bucky on 7/2/2016.
3+
*/

0 commit comments

Comments
 (0)