Created
May 6, 2019 14:58
-
-
Save gatherKnowledge/9efd77aac47e1f6143b381d89876a383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NotifySystem = /** @class */ (function () { | |
function NotifySystem() { | |
this.observList = new Array(); | |
} | |
NotifySystem.prototype.registerObserver = function (o) { | |
this.observList.push(o); | |
}; | |
NotifySystem.prototype.removeObserver = function (o) { | |
this.observList = this.observList.filter(function (x) { return x !== o; }); | |
}; | |
NotifySystem.prototype.notifyObserver = function () { | |
if (this.observList) { | |
this.observList.forEach(function (x) { | |
x.update(); | |
}); | |
} | |
}; | |
return NotifySystem; | |
}()); | |
var ObserveUser1 = /** @class */ (function () { | |
function ObserveUser1() { | |
} | |
ObserveUser1.prototype.update = function () { | |
console.log("1 아이템을 획득했습니다."); | |
}; | |
return ObserveUser1; | |
}()); | |
var ObserveUser2 = /** @class */ (function () { | |
function ObserveUser2() { | |
} | |
ObserveUser2.prototype.update = function () { | |
console.log("2 아이템을 획득했습니다."); | |
}; | |
return ObserveUser2; | |
}()); | |
var notifySystem = new NotifySystem(); | |
var user1 = new ObserveUser1(); | |
var user2 = new ObserveUser2(); | |
console.log('------------------------------------'); | |
notifySystem.registerObserver(user1); | |
notifySystem.registerObserver(user2); | |
notifySystem.notifyObserver(); | |
console.log('------------------------------------'); | |
notifySystem.removeObserver(user1); | |
notifySystem.removeObserver(user2); | |
notifySystem.notifyObserver(); | |
console.log('------------------------------------'); | |
notifySystem.registerObserver(user1); | |
notifySystem.removeObserver(user2); | |
notifySystem.notifyObserver(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ts