我只是想弄清楚如何从以下同一对象的方法中调用 javascript 对象方法。
var testObject = {
method1 : function() {
var connectionAddr = "ws://localhost:8003";
socket = new WebSocket(connectionAddr);
socket.onmessage = function(event) {
method2();
}
},
method2: function() {
this.method1();
}
}
改变了我的问题,因为我在使用 this.method2() 时意识到它指的是 WebSocker 对象。