1 /**
2 * 匿名函数
3 */
4 (function () {
5 /**
6 * 是否启用跟踪用户隐私
7 *
8 * 启用:isPrivacys(true)
9 * 不启用:isPrivacys(false)
10 *
11 */
12 function isPrivacys(isPrivacy) {
13 isPrivacy ? (navigator.msDoNotTrack == "0" || window.doNotTrack == null || navigator.doNotTrack == "unspecified" || navigator.doNotTrack == null) : (navigator.msDoNotTrack || window.doNotTrack || navigator.doNotTrack == '1');
14 }
15
16 // 以释放对象或函数以及变量来提供给其它使用
17 window.isPrivacys = isPrivacys;
18 })();
19
20
21 // 使用它
22 isPrivacys(true);
23
24
25
26 /**
27 * 自执行函数(其实只要裸着就是自执行函数)
28 */
29 !function () {
30 // code....
31 console.log('一开始,我自己执行了!!!');
32 }();
33
34
35
36 /**
37 * 声明式函数 - 运行期上文无法获取
38 * @param {number} a
39 * @param {number} b
40 */
41 var count = function (a, b) {
42 return a + b;
43 }
44 console.log(count(1, 2));
45 count(1, 2);
46
47
48
49
50
51 /**
52 * 函数 - 运行期上下文皆可获取(global)
53 * @param {number} a
54 * @param {number} b
55 */
56 function countAdd(a, b) {
57 return a, b;
58 }