当前位置:网站首页>Change this point to understand
Change this point to understand
2022-07-23 08:08:00 【Mark community】
First of all , We know return You can change this Point to
function Fn(name){ this.name=name; return {};//undefined, Changed the this The direction of , Point to the undefined object } var fn=new Fn(“maomin”); console.log(fn.name);
The other is our common method , Is to give this Assign to a variable .
function fn1(age) { var that=this; that.age=age; console.log(this.age)//21 } fn1(“21”);
But the above method is too low 了 . Next, let's talk about change this Three methods of pointing high :
call()
(1) Anonymous functions can be changed this Point to
12var box=document.querySelector("#box"); box.onclick = function(){ (function(){ console.log(this); //box }).call(this); };
(2) You can inherit methods
function Fn8(name,girlfriend) { this.name=name; this.girlfriend=girlfriend; } function Fn9(name,girlfriend) { Fn8.call(this,name,girlfriend);// The first one is an object , It's the object you want to borrow , In addition to the first parameter, the following parameters are passed into the function as actual parameters . console.log(this.name,this.girlfriend);//maomin, xqm } var fn9=new Fn9(“maomin”,“xqm”);
More on :https://blog.csdn.net/weixin_44519496/article/details/120127993
边栏推荐
- 重链剖分例题配套题解的题解
- Can the formatted data of the USB flash disk be recovered? How to recover the formatted data of the USB flash disk
- 来,滑动到下一个小姐姐
- Flink原理初探和流批一体API(二)v2
- VMware virtual machine changes static IP and hostname, and uses xshell to connect
- How to use C language to realize simple employee information management system
- 剑指Offer | 旋转数组的最小数字
- Learn these SketchUp skills and improve work efficiency by half
- 技术干货 | 基于MindSpore详解Perplexity语言模型评价指标
- 老板要我做一个 IP 属地功能,一个开源库搞定!
猜你喜欢

Redis 事务学习有感

MSG | 开源与结缘,昇思携梦前行!

U盘被格式化数据能恢复吗,U盘被格式化了怎样恢复
![[original dry goods] found a useful tool for data analysis](/img/18/da21520efa77f29d3c2b4890db158d.png)
[original dry goods] found a useful tool for data analysis

使用路由协议配置 IPv6 over IP手动隧道

The boss asked me to do an IP territorial function and an open source library!

QT document reading notes - qaudioinput & qaudioformat parsing and examples

开发者分享|MindSpore Lite 体验,一键实现图像分割

pip更新一个package

老板要我做一个 IP 属地功能,一个开源库搞定!
随机推荐
How to open the file in keil is the real path in the 109th blog of fledgling Xiao Li
图的存储结构及方法(一)
Can PHP split arrays
【读书笔记->统计学】12-01 置信区间的构建-置信区间概念简介
SQL报错盲注实例分析
实验六 MPEG
The boss asked me to do an IP territorial function and an open source library!
Qt+VTK+PCL图片转灰度图且以灰度为Y轴显示
Jmeter查看结果树之查看响应的13种详解方法!
@Transactional transaction methods contain multiple transaction methods of the same kind. These transaction methods themselves are set to fail. There are two solutions
Example analysis of SQL error reporting and blind injection
RequestContextHolder
Can the formatted data of the USB flash disk be recovered? How to recover the formatted data of the USB flash disk
技术干货 | 基于MindSpore详解Perplexity语言模型评价指标
原生js实现dom的获取及操作
Qt+vtk+pcl pictures are converted to grayscale images and displayed with grayscale as the Y axis
php可不可以拆分数组
Using private key to connect to server remotely in pycharm
Building a sylixos environment in VMWare
uni-app进阶之内嵌应用【day14】