第55天 写出4个使用this的典型例子
Activity
wenyejie commentedon Jun 10, 2019
myprelude commentedon Jun 13, 2019
zoggee commentedon Jun 16, 2019
react中constructor中, this.handleClick=this.handleClick.bind(this);
Vi-jay commentedon Jul 31, 2019
补充调用上下文
ipadthree commentedon Sep 13, 2019
censek commentedon Nov 26, 2019
1⃣️ 全局 this 是 window
2⃣️ 函数 this 是调用者
3⃣️ 构造函数的 this 是 new 之后的新对象
4⃣️ call ,apply ,bind 的 this 是第一个参数
https://blog.csdn.net/Bule_daze/article/details/102831150
ZindexYG commentedon Dec 11, 2019
构造函数
call,bind,apply
call 求最值
apply 求最值
bind 使用例子
PS:本例子请在浏览器中使用
azzyx commentedon Oct 26, 2020
smile-2008 commentedon Nov 30, 2020
dugufck666 commentedon Oct 26, 2021
普通函数和定时器,this是window
对象的方法中,this是对象本身
对象的普通属性中的this是全局变量window,在node中global
事件中,谁注册的事件,this就是那个对象
xiaoqiangz commentedon Jun 8, 2022
// 全局作用域
var wid = '全局作用域this'
console.log(this.wid)
// 构造函数
function Person19(name) {
this.name = name
}
// call
var callO = {
wid: 'call this'
}
function sayCallName() {
console.log(this.wid)
}
sayCallName.call(callO)
// apply求值
var arrN = [1,2,3,45,6,2]
console.log(Math.max.apply(this, arrN))
azzyx commentedon Jun 8, 2022
mohaixiao commentedon Jul 8, 2022
(1)在html元素事件属性中使用,如
(2)构造函数
function Animal(name, color) {
This.name = name;
this.color = color;
}
(3)
Var btn = document.getElementById(“text”);
Btn.onclick = function() {
Alert(this.value); //此处的this是按钮元素
}
(4)CSS expression表达式中使用this关键字
azzyx commentedon Jul 8, 2022
2 remaining items