File tree 7 files changed +173
-0
lines changed
7 files changed +173
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+
3
+ < html xmlns ="http://www.w3.org/1999/xhtml ">
4
+ < head >
5
+ < title > Functions</ title >
6
+ < script src ="Scripts/definitions.js " type ="text/javascript "> </ script >
7
+ < script src ="Scripts/immidiate-function.js " type ="text/javascript "> </ script >
8
+ < script src ="Scripts/self-defining-function.js " type ="text/javascript "> </ script >
9
+ < script src ="Scripts/init-time-branching.js " type ="text/javascript "> </ script >
10
+ < script src ="Scripts/Curry.js " type ="text/javascript "> </ script >
11
+ </ head >
12
+ < body >
13
+
14
+ </ body >
15
+ </ html >
Original file line number Diff line number Diff line change
1
+
2
+ ( function ( ) {
3
+ console . log ( "//curry" ) ;
4
+
5
+ function curry ( fn ) {
6
+ var slice = Array . prototype . slice ,
7
+ storedArgs = slice . call ( arguments , 1 ) ;
8
+
9
+ return function ( ) {
10
+ var args = storedArgs . concat ( slice . call ( arguments ) ) ;
11
+ return fn . apply ( null , args ) ;
12
+ }
13
+ }
14
+
15
+ function printMessage ( author , message ) {
16
+ console . log ( author + " say: " + message )
17
+ }
18
+
19
+ var printMyMessage = curry ( printMessage , "me" ) ;
20
+
21
+ printMyMessage ( "I would like to tell you about birds and bees in js world" ) ;
22
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+
2
+ console . log ( "// function definition samples" ) ;
3
+
4
+ //sample a
5
+ ( function ( ) {
6
+ function a ( ) { console . log ( 1 ) ; }
7
+ b = function ( ) { console . log ( 2 ) ; }
8
+ } ) ( ) ;
9
+
10
+ //sample b
11
+ ( function ( ) {
12
+ console . log ( "sample b" ) ;
13
+ b ( ) ;
14
+
15
+ function b ( ) { console . log ( 1 ) ; }
16
+
17
+ /* function b() { console.log(1); }
18
+ * b();
19
+ *
20
+ */
21
+ } ) ( ) ;
22
+
23
+ //sample c
24
+ ( function ( ) {
25
+ console . log ( "sample c" ) ;
26
+ function c ( ) { console . log ( 1 ) ; }
27
+
28
+ c ( ) ;
29
+
30
+ function c ( ) { console . log ( 2 ) ; }
31
+
32
+ /* function c() { console.log(1); }
33
+ * function c() { console.log(2); }
34
+ * c();
35
+ */
36
+ } ) ( ) ;
37
+
38
+ //sample d
39
+ ( function ( ) {
40
+ console . log ( "sample d" ) ;
41
+ try {
42
+ d ( ) ;
43
+
44
+ var d = function ( ) { console . log ( 2 ) ; }
45
+ }
46
+ catch ( e ) {
47
+ console . log ( e )
48
+ }
49
+ /* var d = undefined;
50
+ * d();
51
+ * d = function() { console.log(2); }
52
+ */
53
+ } ) ( ) ;
54
+
55
+ //sample e
56
+ ( function ( ) {
57
+ console . log ( "sample e" ) ;
58
+ var e = function ( ) { console . log ( 1 ) ; }
59
+
60
+ e ( ) ;
61
+
62
+ e = function ( ) { console . log ( 2 ) ; }
63
+ } ) ( ) ;
64
+
65
+ //sample f
66
+ ( function ( ) {
67
+ console . log ( "sample f" ) ;
68
+ var f = function ( ) { console . log ( 1 ) ; }
69
+ f ( ) ;
70
+
71
+ function f ( ) { console . log ( 2 ) ; }
72
+ f ( ) ;
73
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+
2
+ console . log ( "//immidiate function" ) ;
3
+
4
+ //sample a
5
+ ( function ( ) {
6
+ console . log ( "a" ) ;
7
+ } ) ( ) ;
8
+
9
+ //sample b
10
+ ( function ( ) {
11
+ console . log ( "b" ) ;
12
+ } ( ) ) ;
Original file line number Diff line number Diff line change
1
+
2
+ console . log ( "//init-time branching" ) ;
3
+
4
+ // sample bad;
5
+ ( function ( ) {
6
+ function saySomethingClever ( ) {
7
+ var appleTest = / A p p l e / i;
8
+ var googleTest = / G o o g l e / i;
9
+
10
+ if ( appleTest . test ( navigator . vendor ) ) console . log ( "I love apples <3" )
11
+ else if ( googleTest . test ( navigator . vendor ) ) console . log ( "android is everything for me <3" )
12
+ else console . log ( "i love this unpopular corporation too" )
13
+ }
14
+
15
+ saySomethingClever ( ) ;
16
+
17
+ } ) ( ) ;
18
+
19
+ // sample good;
20
+ ( function ( ) {
21
+
22
+ var saySomethingClever ;
23
+
24
+ ( function ( ) {
25
+ var appleTest = / A p p l e / i;
26
+ var googleTest = / G o o g l e / i;
27
+
28
+ if ( appleTest . test ( navigator . vendor ) )
29
+ saySomethingClever = function ( ) { console . log ( "I love apples <3" ) ; }
30
+ else if ( googleTest . test ( navigator . vendor ) )
31
+ saySomethingClever = function ( ) { console . log ( "android is everything for me <3" ) ; }
32
+ else saySomethingClever = function ( ) { console . log ( "i love this unpopular corporation too" ) ; }
33
+ } ) ( ) ;
34
+
35
+ saySomethingClever ( ) ;
36
+
37
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ console . log ( "//self-defining-functions" ) ;
2
+
3
+ function selfDefining ( )
4
+ {
5
+ console . log ( "some really heavy initialization occured" ) ;
6
+ console . log ( "f*ck yeah!" ) ;
7
+ selfDefining = function ( ) {
8
+ console . log ( "job done!" ) ;
9
+ }
10
+ }
11
+
12
+ selfDefining ( ) ;
13
+ selfDefining ( ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ var Singleton_B;
9
9
( function ( ) {
10
10
var instance ;
11
11
var anticlone_proxy ;
12
+
12
13
Singleton_B = function ( ) {
13
14
if ( instance ) { return instance ; }
14
15
You can’t perform that action at this time.
0 commit comments