File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 1+ $ ( "button" ) . click ( function ( ) {
2+ $ ( "p" ) . hide ( "slow" , function ( ) {
3+ alert ( "The paragraph is now hidden" ) ;
4+ } ) ;
5+ } ) ;
Original file line number Diff line number Diff line change 1+ # Title
2+
3+ Description
Original file line number Diff line number Diff line change 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 ( ) ) ;
You can’t perform that action at this time.
0 commit comments