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>

 

posted @ 2017-04-26 20:22  少海  阅读(101)  评论(0)    收藏  举报