Skip to content

Commit

Permalink
Update 2014-01-19-the-usage-of-this-in-javascript.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezlk authored Jul 22, 2016
1 parent 3477adc commit 05708a5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _posts/2014-01-19-the-usage-of-this-in-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ category: tech
this.myName = "Foo function.";
}
foo.prototype.sayHello = function(){
self = this; //将bar中的this的值存在变量self中,这样self所指向的对象就跟bar中的this一样了。
alert(this.myName);
}
foo.prototype.bar = function(){
self = this; //将bar中的this的值存在变量self中,这样self所指向的对象就跟bar中的this一样了。
setTimeout(self.sayHello, 1000);
}
var f = new foo;
f.bar();
f.bar();

0 comments on commit 05708a5

Please sign in to comment.