2
2
title : Beware Anonymous Functions
3
3
level : beginner
4
4
source : http://jqfundamentals.com/legacy
5
- attribution :
5
+ attribution :
6
6
- jQuery Fundamentals
7
7
---
8
8
@@ -13,44 +13,33 @@ your handlers and callbacks.
13
13
// BAD
14
14
$( document ).ready(function() {
15
15
16
- $("#magic").click(function( event ) {
16
+ $( "#magic" ).click(function( event ) {
17
+ $( "#yayeffects" ).slideUp(function() {
18
+ // ...
19
+ });
20
+ });
17
21
18
- $("#yayeffects").slideUp(function() {
19
-
20
- // ...
21
-
22
- });
23
-
24
- });
25
-
26
- $("#happiness").load( url + " #unicorns", function() {
27
-
28
- // ...
29
-
30
- });
22
+ $( "#happiness" ).load( url + " #unicorns", function() {
23
+ // ...
24
+ });
31
25
32
26
});
33
27
34
28
// BETTER
35
29
var PI = {
36
30
37
- onReady : function() {
38
-
39
- $("#magic").click( PI.candyMtn );
40
-
41
- $("#happiness").load( PI.url + " #unicorns", PI.unicornCb );
42
-
43
- },
44
-
45
- candyMtn : function( event ) {
46
-
47
- $("#yayeffects").slideUp( PI.slideCb );
31
+ onReady: function() {
32
+ $( "#magic" ).click( PI.candyMtn );
33
+ $( "#happiness" ).load( PI.url + " #unicorns", PI.unicornCb );
34
+ },
48
35
49
- },
36
+ candyMtn: function( event ) {
37
+ $( "#yayeffects" ).slideUp( PI.slideCb );
38
+ },
50
39
51
- slideCb : function() { ... },
40
+ slideCb: function() { ... },
52
41
53
- unicornCb : function() { ... }
42
+ unicornCb: function() { ... }
54
43
55
44
};
56
45
0 commit comments