<script>/*如何指定this的值可以通过2类方法指定1.调用时指定1.1call方法1.2apply方法2.创建时指定2.1bind方法2.2箭头函数*/// ------1.调用时指定------//1.1call方法:挨个传入参数//1.2apply方法:数组形式传入参数function foo (numA, numB) {console.log(this)console.log(numA, numB)}const obj = {name: "obj"}foo.call(obj, 10, 20)foo.apply(obj, [10, 20])// ------2.创建时指定------// 2.1bind方法foo.bind(obj, 30, 30)() // 30, 30const newF = foo.bind(obj, 30, 40)newF() // 30, 40// 2.2箭头函数const food = {name: "西兰花",getFood: function () {console.log(this, 'this')//foodsetTimeout(() => {console.log(this)//food}, 1000)//箭头函数// setTimeout(function () {// console.log(this)//windows// }, 1000) //不是箭头函数}}food.getFood()</script>