TypeScript消息通知实战指南 - 这是一个测试消息'
TypeScript消息通知实战指南
NotificationService
NotificationServicesendNotification
class NotificationService {
private message: string;
constructor(message: string) {
this.message = message;
}
public sendNotification(notification: string): void {
console.log('发送消息:', notification);
}
}
MessageReceiverreceiveNotification
class MessageReceiver {
private notificationService: NotificationService;
constructor() {
this.notificationService = new NotificationService('这是一个测试消息');
}
public receiveNotification(notification: string): void {
console.log('接收到消息:', notification);
}
}
main
function main(): void {
const receiver = new MessageReceiver();
receiver.receiveNotification('这是一个测试消息');
receiver.receiveNotification('这是另一个测试消息');
}
main();
运行上述代码,你将看到以下输出:
发送消息: 这是一个测试消息
接收到消息: 这是另一个测试消息
NotificationServiceMessageReceiver 拼多多帮助力入口