求教.不知道该怎么拟标题 - - function methodObj(){ this.p1; this.p2 = (function(){ return this.p1 * 2; })(); }var obj = new methodObj();alert(obj.p2); // obj.p2 value is undefined想问的是红色字体部分.正确的写法应该是怎样的? 函数体内引用不到 this.p1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function methodObj(){ this.p1; this.p2 = (function(){ return this.p1 * 2; })(); }var obj = new methodObj();alert(obj.p2); // obj.p2 value is undefined 域不一样,this指向不同你可以把this.p1作为参数传进去,如:this.p2 = (function(x){return x* 2;})(this.p1);或定义一变量,如:var x = this.p1; this.p2 = (function(){return x* 2;})(); 有办法使嵌套函数的域指向被嵌套的函数里吗?用call什么的.有办法实现吗 <script>function methodObj(){ this.p1=2 this.p2 = function(arg){return arg * 2}.call(this, this.p1)}var obj = new methodObj();alert(obj.p2); // obj.p2 value is undefined</script> this.p2 = (function(){ return this.p1 * 2; }).call(this); 帮忙改下这个正则 复选框与文本框传值问题 求助高手,如何通过脚本修改IE的安全设置!! 关于document.all()方法的问题 [help]点击按实现-选择"选择框"的值 求解读关于瀑布流加载的JS代码问题? 请问在JavaScript里怎么取得系统时间???谢谢大家了!!! 怎样在html页面上直接进行添加、删除、修该操作!(特别着急!) 如何设置IE打印设置中 页面大小 对应注册表项? 怎么把一个集合添加到另一个集合中? 实现一个比较绕的效果,希望各位帮忙写出来!!! 比较棘手的问题,解决立即给分!(100分)
this.p1;
this.p2 = (function(){
return this.p1 * 2;
})();
}var obj = new methodObj();alert(obj.p2); // obj.p2 value is undefined
你可以把this.p1作为参数传进去,如:this.p2 = (function(x){return x* 2;})(this.p1);
或定义一变量,如:var x = this.p1; this.p2 = (function(){return x* 2;})();
function methodObj(){
this.p1=2
this.p2 = function(arg){return arg * 2}.call(this, this.p1)
}var obj = new methodObj();alert(obj.p2); // obj.p2 value is undefined
</script>
return this.p1 * 2;
}).call(this);