12345678910111213141516171819202122232425262728293031323334 |
- var box = document.getElementById("box");
- // 点击事件 当前元素中引用谁 this就指向谁
- // box.onclick = function() {
- // console.log(this)
- // }
- // 在定时器中 this指向全局变量 window
- // box.onclick = function() {
- // setInterval(function(){
- // console.log(this);
- // },1000)
- // }
- // 在对象中 this指向当前对象的本身
- // var obj = {
- // name: 'LiLi',
- // sex: '女',
- // age: function() {
- // console.log(this);
- // }
- // }
- // obj.age();
- // 在函数里 this指向window
- function fn1() {
- console.log(this);
- }
- fn1();
|