Dev/JavaScript
javascript prototype class 사용시 jquery 에서 "this" 사용하는 방법
프리지앙
2013. 3. 20. 15:28
javascript 를 prototype 을 이용해서 class 를 생성해서 사용할 경우
jQuery 안에서 자신객체인 "this" 를 사용할 수 없는데 아래와 같이 해결 할 수 있다.
game = function () {
this.type = "item";
}
this.type = "item";
}
game.prototype.clicks = function () {
var self = this;
$("#btn_click").click(function () {
alert(self.type);
}
}
var self = this;
$("#btn_click").click(function () {
alert(self.type);
}
}
"var self = this;" 이런 방법으로 사용하면 된다.