<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="con">ddd</div>
</body>
<script>
// function() { }
// es6 箭头函数
// 1.把function 去掉
// 2.在()与{ } 添加箭头
// () => { }
// function (item, i) { }
// (item, i) => { }
// function() { return "hello"; }
// () => { return "hello"; }
// 若有返回值 {} 与 return 还可以省略
// () => "hello"
// 若参数只有一个 () 还可省略
// function(item) { return item }
// item => item
// function() { return a + b };
// () => { return a + b }
// () => a + b;
// function(a, b) { return a + b };
// (a, b) => { return a + b; }
// (a, b) => a + b;
// function(a) { return a };
// (a) => a;
// a => a;
// arr.forEach(function (item, i, arr) { console.log(item); })
// arr.forEach((item, i, arr) => { console.log(item); })
// arr.filter(function (item, i) { return arr.indexOf(item) === i })
// arr.filter((item, i) => arr.indexOf(item) === i)
// arr.map(function (item) { return item; })
// arr.map(item => item)
// function box() { }
// var box = () => { console.log(this); }
// var box = function(){}
// box();
var oDiv = document.getElementById("con");
function box(a, b) {
console.log(this);//window oDiv
// this.innerHTML = "HELLO WROLD";
return () => this;
// return function () {
// return this;
// };
}
// console.log(box.call(oDiv)()); //box()() 闭包里的this 指向window对象
// console.log(box.call(oDiv, null)());
// console.log(box());//window
// window.box(2,6)
// box.call(oDiv, 2, 6);//强制修改函数box内部的this指向
// box.apply(oDiv, [2, 6]);//强制修改函数box内部的this指向
// box.bind(oDiv) // box
// box.bind(oDiv, [2, 6])() // box()
// console.log();
// 函数名.call(参数1,参数2)
// 参数1:函数内部的this强制指向的对象
// 参数2:函数的实参 多个实参间用逗号隔开
// 函数名.apply(参数1,参数2)
// 参数1:函数内部的this强制指向的对象
// 参数2:数组 函数的实参组成的数组
// 函数名.bind(参数1,参数2)
// 参数1:函数内部的this强制指向的对象
// 参数2:数组 函数的实参组成的数组
// 返回: 函数
// 调用函数
// 函数名.bind(参数1,参数2)()
// console.log(box()());//window
// function () {
// return this;
// };
// function Box() {
// }
// var Box = () => { }
</script>
</html>