Skip to content

Commit

Permalink
Add clone function
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 27, 2015
1 parent 9989abf commit 688bba7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Expand Up @@ -204,4 +204,16 @@ Kareem.prototype.post = function(name, fn) {
return this;
};

Kareem.prototype.clone = function() {
var n = new Kareem();
for (var key in this._pres) {
n._pres[key] = this._pres[key].slice();
}
for (var key in this._posts) {
n._posts[key] = this._posts[key].slice();
}

return n;
};

module.exports = Kareem;
12 changes: 12 additions & 0 deletions test/examples.test.js
Expand Up @@ -325,3 +325,15 @@ describe('createWrapper()', function() {
});
});
});

describe('clone()', function() {
it('clones a Kareem object', function() {
var k1 = new Kareem();
k1.pre('cook', function() {});
k1.post('cook', function() {});

var k2 = k1.clone();
assert.deepEqual(['cook'], Object.keys(k2._pres));
assert.deepEqual(['cook'], Object.keys(k2._posts));
});
});

0 comments on commit 688bba7

Please sign in to comment.