我有以下情况。在伪类的构造函数中,我将单击事件附加到元素。触发事件时,我想从回调函数引用设置事件的对象。
伪类构造函数代码
function MyClass(){
this.myClassAttribute = "A class attribute";
// here `this` refers to the object
$("span").click(function(){
// here `this` refer to a matched element, i.e. "span"
// How to get the value of `myClassAttribute`?
});
}
如何在没有全局变量的情况下引用对象?