问个很菜的问题,代码如:function c1(){
this.o1=100;
function p1(){
return this.o1+42
}
function p2(){
return 52
}
this.q1=p1()+1;
this.q2=p2()+2;
}
a1=new c1()
alert(a1.q1);//NaN
alert(a1.q2);//54为什么p1()调用的this.o1会无效呢?p1()的作用域在哪?
this.o1=100;
function p1(){
return this.o1+42
}
function p2(){
return 52
}
this.q1=p1()+1;
this.q2=p2()+2;
}
a1=new c1()
alert(a1.q1);//NaN
alert(a1.q2);//54为什么p1()调用的this.o1会无效呢?p1()的作用域在哪?
解决方案 »
- JavaScript table 问题
- 使用Ext.Ajax.request({}) 查询后台时,有值时赋值,无值时,可以让用户自己输入???
- 求教一个问题,先谢谢大家帮我看看!!!
- 有没有办法把exe运行的界面嵌在web页面中?有限制的exe也行,比如.net之类的
- hbhbhbhbhb1021(天外水火(我要多努力)) 来拿分
- 如何让日期动态显示???
- 孟兄,各位高手,ondbclick怎么不起作用?
- 关于window.open()的一个小问题。
- 请教:关于<input type=image name="submit" value="submit" src="image.gif">写法的2个疑问!!!
- 新人求助:外部JS为什么在浏览器不能显示
- 关于窗口与窗口之间传值的问题
- 请教一个翻译问题
function c1(){
this.o1=100;
var $this = this;
function p0(){
return $this.o1+42
}
function p1(){
return this.o1+42//这里this是代表p1而不是c1
} function p2(){
return 52
}
this.q0=p0();
this.q1=p1()+1;
this.q2=p2()+2;
}
a1=new c1()
alert(a1.q0);
alert(a1.q1);//NaN
alert(a1.q2);//54
this始终指向到调用它的对象。<script type="text/javascript">function c1(){
this.o1=100;
function p1(){
alert(arguments.callee.caller==c1);//p1中的this始终指向到c1
return this.o1+42
}
function p2(){
alert(arguments.callee.caller==c1);//p2中的this始终指向到c1
return 52
}
this.q1=p1()+1;
this.q2=p2()+2;
}alert(c1.o1);//c1未被实例化的时候无法访问到构造内部的属性。var a = new c1();alert(a.o1+'\n'+a.q1+'\n'+a.q2);</script>
alert(arguments.callee.caller);//c1的调用对象是window
//other...
}
this.o1=100;
function p1(){
return this.o1+42
}
function p2(){
return 52
}
this.q1=p1()+1;
this.q2=p2()+2;
}
a1=new c1()
alert(a1.q1);//NaN
alert(a1.q2);//54this其实是window
并不是调用它的对象哦
function c1(){
this.o1=100;
this.p1 = function(){
return this.o1+42
}
function p2(){
return 52
}
this.q1=this.p1()+1;
this.q2=p2()+2;
}a1=new c1()
alert(a1.q1);//NaN
alert(a1.q2);//54
window.o1 = 1;function c1(){
this.o1=100;
function p1(){
alert(arguments.callee.caller);
return this.o1
}
this.p2=function(){
alert(arguments.callee.caller);
return this.o1
}
this.q1=p1()+1;
this.q2=this.p2()+2;
}
a1=new c1()
alert(a1.q1);//NaN
alert(a1.q2);//54两个的this不是同一个对象但arguments.callee.caller都是相同的
解析不了this吧