我知道如果对象是一个函数,我可以用闭包(var self = this)来做到这一点......
<a href="#" id="x">click here</a>
<script type="text/javascript">
var object = {
y : 1,
handle_click : function (e) {
alert('handling click');
//want to access y here
return false;
},
load : function () {
document.getElementById('x').onclick = this.handle_click;
}
};
object.load();
</script>