Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var observableText = {
- observers: [],
- text: "",
- notifyAll: function(o){
- for (var j = 0; j < this.observers.length; j++){
- this.observers[j].update(this.text);
- }
- },
- addObserver: function(o){
- this.observers.push(o);
- },
- updateText: function(t){
- this.text = t;
- this.notifyAll();
- }
- };
- var displayText = {
- text: "",
- update: function(t){
- this.text = t;
- console.log(this.text);
- }
- }
- observableText.addObserver(displayText);
- observableText.updateText("updated once");
- observableText.updateText("updated twice");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement