// 探索作用域this,箭头函数域普通函数的区别
// 箭头函数的定义是保证函数里的this是是定义域的this,
// 如果调用他的对象没有该函数,依旧会报undefined is not a Function
function scopeOfFuns(){
console.log("out fun:",this);
function scopeOfFunIn(){
console.log("in funs:",this)
}
scopeOfFunIn();
}
const scopeOfArrowFuns = () => {
console.log("arrow fun out:",this);
const scopeOfArrowFunsIn = () => {
console.log("arrow fun in",this);
}
scopeOfArrowFunsIn();
}
const scopeOfArrowFuns1 = () => {
console.log("arrow fun out:",this);
function scopeOfArrowFunsIn(){
console.log("arrow fun in",this);
}
scopeOfArrowFunsIn();
}
function scopeOfFuns1(){
console.log("out fun:",this);
const scopeOfFunIn = () => {
console.log("in funs:",this)
}
scopeOfFunIn();
}
function funTest() {
const scopeOfFunIn = () => {
探索函数作用域(普通函数与箭头函数的区别)
最新推荐文章于 2023-08-10 18:26:01 发布
本文详细探讨了JavaScript中的函数作用域,对比了普通函数与箭头函数的区别,揭示了它们在作用域、this指向等方面的不同,帮助开发者更好地理解和使用这两种函数形式。
摘要由CSDN通过智能技术生成