又丢脸了...

偷一下懒去看js的资料,然后跟着做了个demo。然后写了一个测试,发现不行。

 

我傻了很久,于是,我到stack上提问了。提问之前有点怕,因为提问不好会被扣分的。stack的速度果然快,一会就有几个人回答了。这是我的测试代码:

 

	var body =document.body;
		var obj = {
			value : 7,
			a : function(){
			    _this = this; //this refer to object obj
				body.onclick = function(){
					_this.b(); // this refer to body Element ,_this refer to object obj
				};
			},
			b : function(){
				alert(this.value);
			}
		}
		obj.a();

  

代码是All correct,只是我把它放在一个空的body里面,没有内容,所以点击的时候没有反应。

 

又傻逼了一回。

posted @ 2012-05-09 17:42  e.e.p  阅读(200)  评论(0编辑  收藏  举报