【发布时间】:2014-04-28 15:09:44
【问题描述】:
我正在使用一种网络通知系统,我想为每个通知创建一个对象,以便跟踪未读或已读通知。 例如,我得到了这样的东西:
var Notifications = function(){
this.read = false;
};
Notifications.prototype.open = function(){
alert('opening');
}
Notifications.prototype.close = function(){
alert('close');
}
Notifications.prototype.fetchInfo = function(){
alert('fetching info from browser');
}
Notifications.prototype.remove = function(){
alert('removing notification');
}
var someNotification = new Notification();
我真正想要做的是每次来自套接字的 resiebe 事件创建一个新的通知,例如:
socket.on('notification', function(){
var notification1 = new Notification();
});
现在如果收到新通知,则创建
var notification2 = new Notifications();
我想知道我可以动态地创建这个通知对象,或者如果你们知道更好的方法来处理这个问题,我感谢你们的帮助。
【问题讨论】:
标签: javascript oop object inheritance