Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var counter = 0;
- function Ant(name) {
- this.name = name;
- this.id = ++counter;
- }
- Ant.meets = {}
- Ant.prototype.hello = function (other) {
- if (!Ant.meets[this.id]) {
- Ant.meets[this.id] = []
- }
- Ant.meets[this.id].push({name: other.name, date: new Date()});
- };
- Ant.prototype.about = function () {
- var name = this.name;
- var meets = Ant.meets[this.id].map(function (meet) {
- return 'My name is ' + name + '. I met ' + meet.name + ' at ' + meet.date;
- });
- return meets.join('\n');
- }
- var ant1 = new Ant('ant1');
- var ant2 = new Ant('ant2');
- var ant3 = new Ant('ant3');
- ant1.hello(ant3); // встреча
- setTimeout(function(){
- ant2.hello(ant3); // встреча
- setTimeout(function(){
- ant3.hello(ant1); // встреча
- console.log('ant1',ant1.about()); // просим рассказать о себе и встречах
- console.log('ant2',ant2.about()); // просим рассказать о себе и встречах
- console.log('ant3',ant3.about()); // просим рассказать о себе и встречах
- },2000);
- },2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement