init
This commit is contained in:
107
Html-Javascript/16-函数进阶.html
Normal file
107
Html-Javascript/16-函数进阶.html
Normal file
@@ -0,0 +1,107 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
//00-return
|
||||
|
||||
// function func0(){
|
||||
// return "小屁孩";
|
||||
// console.log('return之后的代码,不会再执行')
|
||||
// }
|
||||
|
||||
// //01-递归
|
||||
// function quyu (m,n){
|
||||
// let num;
|
||||
// if(m<n) num=m;
|
||||
// if(m==n) mun=0;
|
||||
// if(m>n) {
|
||||
// num=quyu(m-n,n);
|
||||
// }
|
||||
// return num;
|
||||
// }
|
||||
// console.log(quyu(10,4));
|
||||
|
||||
|
||||
|
||||
//02-arguments
|
||||
// function func1(){
|
||||
// // auguments.__proto__= Array.prototype
|
||||
// console.loh(arguments);
|
||||
// console.dir(Array);
|
||||
// // arguments.array.forEach(element => {
|
||||
// // console.log(element);
|
||||
// // });
|
||||
// // }
|
||||
// func1(1,2,3,"第四参数",{c:"第五参数"});
|
||||
|
||||
|
||||
//03-闭包
|
||||
// function outer (){
|
||||
// var a=0;
|
||||
// function inner(){
|
||||
// a++;
|
||||
// return a;
|
||||
// }
|
||||
// return inner;
|
||||
// }
|
||||
// let f1 =outer();
|
||||
// let f2= outer();
|
||||
// console.log(f1());
|
||||
// console.log(f2());
|
||||
// console.log(f1());
|
||||
// console.log(f2());
|
||||
// console.log(f1());
|
||||
// console.log(f2());
|
||||
|
||||
|
||||
|
||||
|
||||
// 04-this
|
||||
//谁调用它 它 的this就是谁
|
||||
|
||||
function f(){
|
||||
console.log(this);
|
||||
|
||||
}
|
||||
|
||||
//它定义于哪个地方 它的this就属于谁 这种定义不能修改
|
||||
let g = () =>
|
||||
{
|
||||
console.log(this);
|
||||
}
|
||||
f(); //window
|
||||
g(); //window
|
||||
|
||||
let o = {
|
||||
f,
|
||||
g
|
||||
}
|
||||
let me = {name:"me"};
|
||||
o.f();//o 对象
|
||||
o.g();//window
|
||||
|
||||
|
||||
//我命由我不由天
|
||||
//call
|
||||
o.f.call(me,"参数一","参数二");
|
||||
o.f.apply(me,[,"参数一","参数二"]);
|
||||
|
||||
//bind 拷贝这个函数,映射
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user