Created
July 10, 2014 13:21
-
-
Save ixth/339da337228d5f29679f to your computer and use it in GitHub Desktop.
Белка.прячьОрехи
This file contains hidden or 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
function Белка(орехи) { | |
this.орехи = []; | |
if (орехи.length) { | |
this.получиОрехи(орехи); | |
} | |
} | |
Белка.prototype.получиОрехи = function (орехи) { | |
Array.prototype.push.apply(this.орехи, орехи); | |
}; | |
Белка.prototype.прячьОрехи = function (вДереве) { | |
var орехи = this.орехи.pop(); | |
if (!орехи) { | |
throw Error('Беда!'); | |
} | |
return вДереве.прячь(орехи); | |
}; | |
var белка = new Белка(['o','o','o']); | |
var заначка = белка.прячьОрехи(new Дерево()); |
This file contains hidden or 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
function Дерево() { | |
this.дупло = []; | |
} | |
Дерево.prototype.прячь = function (орехи) { | |
this.дупло.push(орехи); | |
return this; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment