AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
函数执行的时候,this,谁调用的,this就指向谁,默认是window 题目一: ```js function a() { function b() { console.log(this); // 未指明调用的对象,因此是 window function c() { "use strict" console.log(this); // 严格模式 this 为 undefined } c() } b() } a() ``` 题目二: ```js var name = '小白' function special() { console.log('姓名:' + this.name); } var girl = { name: '小红', detail: function() { console.log('姓名:' + this.name); }, woman: { name: '小黄', detail: function() { console.log('姓名:' + this.name); } }, special } girl.detail() // 小红 girl.woman.detail() // 小黄 girl.special() // 小红 ``` 题目三: ```js var name = '小红' function a() { var name = '小白' console.log(this.name); } function d(i) { return i() } var b = { name: '小黄', detail: function() { console.log(this.name); }, bibi: function() { return function() { console.log(this.name); } } } var c = b.detail b.a = a var e = b.bibi() a(); // 小红 c() // 小红 b.a() // 小黄 d(b.detail) // 红 e() // 红 ```