的愈來愈未捕獲的參考錯誤:「消息」沒有被定義, 這裏是代碼:未捕獲的ReferenceError:X是未定義
class ChatApp {
constructor(){
//console.log('ChatApp constructor');
socket.init('ws://localhost:8000');
socket.registerOpenHandler(() => {
let message = new ChatMessage({ message: 'Hello' });
socket.sendMessage(message.serialize());
});
socket.registerMessageHandler((data) => {
console.log(data);
});
}
}
class ChatMessage {
constructor({
message: m,
user: u='Nader',
timestamp: t=(new Date()).getTime()
}) {
this.message = message;
this.user = user;
this.timestamp = timestamp;
console.log(message);
}
serialize(){
return {
message: this.message,
user: this.user,
timestamp: this.timestamp
};
}
}
雖然我使用讓消息行5定義的消息.... 請幫忙,謝謝
你一定要明白你解構過程中重命名?它不是'消息'。 – Li357
「user」和「timestamp」相同。 –
@Andrew李你是正確的 – Ned007