如果我在 jQuery 事件中,我不确定如何访问类变量。下面的例子
// <reference path="../typings/jquery/jquery.d.ts" />
export class Notes {
// I want to access this inside of the click event
test = "test";
foo() {
//works here
alert(this.test);
$("#testDiv").click(function () {
// context of this changes so this no longer works
alert(this.test);
// How do I access the test variable in here?
})
}
}