Skip to content

Commit 9d69708

Browse files
committed
Updated code
1 parent 60c5bd3 commit 9d69708

5 files changed

Lines changed: 50 additions & 0 deletions

File tree

Callback/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Callback
2+
3+
A callback is a function that is called after another function is done executing.
4+
Good for when you are making API calls, and want function to run only after data is retrieved from server.

Callback/index.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Callbacks</title>
6+
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
7+
</head>
8+
<body>
9+
10+
<button>Hide</button>
11+
<p>This is a paragraph with little content.</p>
12+
13+
<script>
14+
$("button").click(function () {
15+
$("p").hide("slow", function () {
16+
alert("The paragraph is now hidden");
17+
});
18+
});
19+
</script>
20+
21+
</body>
22+
</html>

Callback/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$("button").click(function(){
2+
$("p").hide("slow", function(){
3+
alert("The paragraph is now hidden");
4+
});
5+
});

Prototype/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

Prototype/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// We could create a function inside Person(), but then we would have a copy of that function for every instance
2+
function Person(first, last) {
3+
this.firstName = first;
4+
this.lastName = last;
5+
}
6+
7+
// Instead we can use prototype to load the function only once in memory (no matter how many Person objects we have)
8+
Person.prototype.getName = function () {
9+
return this.firstName + " " + this.lastName;
10+
};
11+
12+
var bucky = new Person('Bucky', 'Roberts');
13+
var emily = new Person('Emily', 'Jones');
14+
15+
console.log(bucky.getName());
16+
console.log(emily.getName());

0 commit comments

Comments
 (0)