前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >看了这篇我也懂了this

看了这篇我也懂了this

作者头像
马克社区
发布2022-07-20 17:29:29
发布2022-07-20 17:29:29
1440
举报
文章被收录于专栏:高端IT高端IT

// this指向 // 1.指向全局变量window var a = 1;

function func() { var a = 2; console.log(this.a); } func(); //2 // 2.指向调用它的对象(funx()中的this只对直属上司(直接调用者obj)负责,不管有多少个。) var b = 3;

function funx() { console.log(this.b); } var obj = { b: 4, funx } obj.funx(); //4

var aa = 15

function test() { console.log(this.aa) } var obj = { aa: 2, test } var obj0 = { aa: 3, obj } obj0.obj.test() // 3.可以将其传给一个变量,并且一样调用它 var d = 1

function test() { console.log(this.d) } var obj = { d: 2, test } var testCopy = obj.test testCopy(); // 4.call(),命令指向谁 var e = 7;

function test1() { console.log(this.e) } var obj = { e: 8, test1 } var testCopy = obj.test1 testCopy.call(obj); // 5.指向构造函数实例化对象

更多请见:https://blog.csdn.net/weixin_44519496/article/details/120126852

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档