如何解决JS在类的外部定义按钮的onclick事件时this的指向错误?

this会指向按钮,但是我希望它指向类。
具体情况:
下面的对象会创建一个按钮,我希望点击按钮弹出“测试”,但事实上没反应,因为按钮onclick中的this没有指向类。

function OBJ(){
    this.X="测试";
    this.按钮=document.createElement("input");
    this.按钮.type="button";
    this.按钮.value="测试";
    document.body.appendChild(this.按钮);
}
OBJ.prototype.按钮.onclick=function (){
    alert(this.X);
}

改成这样就好了:

function OBJ(){
    this.X="测试";
    this.按钮=document.createElement("input");
    this.按钮.type="button";
    this.按钮.value="测试";
    document.body.appendChild(this.按钮);
    var self=this;
    this.按钮.onclick=function (){
        alert(self.X);
    }
}

但是我不想在OBJ内部书写onclick,我想使用prototype来在外部书写、从而增加代码的可维护性。我该怎么做?

var that = this;
然后用that代替this