码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript的this用法

时间:2014-10-17 11:45:24      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   ar   java   sp   div   2014   


1. 全局代码中的this 

      this在全局上下文中,它的值是全局对象本身(Global Object),在浏览器中就是Window  Object,如下图示。

      bubuko.com,布布扣

      看下面几个例子:

//Global scope
//
The implicit property of the global object 
var foo1 = "abc";
console.log(this.foo1 == window.foo1); console.log(foo1); console.log(this.foo1); console.log(window.foo1);  //true abc abc abc
 
//The implicit property of the global object 
foo2 = "def";  
console.log(this.foo2 == window.foo2); console.log(foo2); console.log(this.foo2); console.log(window.foo2);      //true def def def
 
//The explicit property of the global object 
this.foo3 = "gh";  
console.log(this.foo3 == window.foo3); console.log(foo3); console.log(this.foo3); console.log(window.foo3); //true gh gh gh

 

2.  


 

JavaScript的this用法

标签:style   blog   http   color   ar   java   sp   div   2014   

原文地址:http://www.cnblogs.com/sun-mile-rain/p/4030438.html

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