码迷,mamicode.com
首页 > 其他好文 > 详细

this

时间:2016-08-12 00:44:03      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

什么是this

this是js中的一个关键字。它是函数运行时自动生成的一个内部对象,代表指向,只能在函数内部使用。

函数被直接调用,this指向window。

1 function fn(){
2     console.log(this);//window
3 }
4 fn();

当函数被事件调用,并且是以赋值的方式出现,谁调用了函数,this就指向谁 。

1 document.onclick=function(){
2     console.log(this);//document
3 };

 

this

标签:

原文地址:http://www.cnblogs.com/imguo/p/5762986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!