Skip to content

Commit fb7a1f8

Browse files
committed
update
1 parent e494998 commit fb7a1f8

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

Example/array.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>排序问题</title>
6+
</head>
7+
<body>
8+
<script type="text/javascript">
9+
var arr = [1,5,2,7,4,3]
10+
</script>
11+
</body>
12+
</html>

Example/bibao.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//函数作为返回值
2+
function F1() {
3+
var a = 100;
4+
return function () {
5+
console.log(a); //自由变量 回去父作用域寻找
6+
}
7+
}
8+
var f1 = F1();
9+
var a = 200;
10+
f1() // 100
11+
12+
//2.函数作为参数来传递
13+
function F1() {
14+
var a = 100;
15+
return function () {
16+
console.log(a); // 自由变量,父作用域寻找
17+
}
18+
}
19+
20+
var f1 = F1();
21+
22+
function F2(fn) {
23+
var a = 200;
24+
fn();
25+
}
26+
27+
F2(f1);
28+
29+
//从以上可以看出闭包应用的时候可以收敛作用域
30+
//实际应用中使用闭包封装变量,收敛权限
31+
function isFirstLoad() {
32+
var _list = [];
33+
return function (id) {
34+
if (_list.indexOf(id) >= 0) {
35+
return false;
36+
}else {
37+
_list.push(id);
38+
return true;
39+
}
40+
}
41+
}

Example/opp.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
var s2 = new Child2();
4747
console.log(s1.play,s2.play);
4848
s1.play.push(4);
49+
4950
//组合方式
5051
function Parent3() {
5152
this.name = 'Parent3';
@@ -55,6 +56,7 @@
5556
Parent3.call(this);
5657
this.type = 'Child3';
5758
}
59+
5860
//子类化原型链 执行了两次实例化
5961
Child3.prototype = new Parent3();
6062
var s3 = new Child3();

Example/yxl.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Elem(id) {
2+
this.elem =document.getElementById(id);
3+
}
4+
5+
//获取html原型
6+
Elem.prototype.html = function (val) {
7+
var elem = this.elem;
8+
if (val) {
9+
elem.innerHTML = val;
10+
return this //链式操作 后部可以继续操作,因为对象还是通过id
11+
}else {
12+
return elem.innerHTML;
13+
}
14+
}
15+
16+
Elem.prototype.on = function (type,fn,bool) {
17+
var elem = this.elem;
18+
elem.addEventListener(type,fn,bool);
19+
}
20+
21+
var div1 = new Elem('div1');
22+
23+
console.log(div1.html());
24+
25+
var i,a;
26+
for (var i = 0; i < 10; i++) {
27+
(function (i) {
28+
var a = document.createElement('a');
29+
a.innerHTML = i + '<br>';
30+
a.addEventListener('click',function (e) {
31+
e.preventDefault();
32+
alert(i);
33+
})
34+
document.body.appendChild(a);
35+
})(i)
36+
}

Example/事件代理.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>事件委托</title>
6+
</head>
7+
<body>
8+
<ul id="ul">
9+
<li data-type="1"></li>
10+
<li data-type="2"></li>
11+
<li data-type="3"></li>
12+
<li data-type="4"></li>
13+
<li data-type="5"></li>
14+
</ul>
15+
</body>
16+
<script type="text/javascript">
17+
document.getElementById("ul").addEventListener("click",function (e) {
18+
// e.target是被点击元素
19+
if(e.target && e.target.nodeName == "LI"){
20+
//找到目标,输出ID!
21+
console.log(e.target.getAttribute('data-type'));
22+
}
23+
})
24+
</script>
25+
</html>

Example/自定义事件.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>自定义事件</title>
6+
</head>
7+
<body>
8+
<li id="ev"></li>
9+
<script type="text/javascript">
10+
var ev = document.getElementById('ev');
11+
var eve = new Event('custome');
12+
ev.addEventListener('custome',function () {
13+
console.log('custome');
14+
});
15+
ev.dispatchEvent(eve);
16+
</script>
17+
</body>
18+
</html>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,9 @@ function insertionSort() {
19541954
 }
19551955
```
19561956

1957+
##
1958+
### JS性能优化
1959+
*
19571960
---
19581961

19591962
### JSDemo JS小程序

0 commit comments

Comments
 (0)