Skip to content

Instantly share code, notes, and snippets.

@ixth
Created July 10, 2014 13:21
Show Gist options
  • Save ixth/339da337228d5f29679f to your computer and use it in GitHub Desktop.
Save ixth/339da337228d5f29679f to your computer and use it in GitHub Desktop.
Белка.прячьОрехи
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 Дерево());
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