this啥时候会出问题? 1.定时器 2.事件
1.定时器
<script>
function Aaa()
{
var _this = this;
this.a = 12;
setInterval(function(){
_this.show();
}, 3000);
}
Aaa.prototype.show = function()
{
alert(this.a);
};
var obj = new Aaa();
</script>
2.事件
function Bbb()
{
var _this = this;
this.b = 5;
document.getElementById('btn1').onclick = function ()
{
_this.show();
};
};
Bbb.prototype.show = function()
{
alert(this.b);
};
window.onload = function()
{
new Bbb();
};
</script>

浙公网安备 33010602011771号