Permalink
Browse files

Adds new clone function

  • Loading branch information...
1 parent 59e830a commit c88d1e935905a326796e7bcef60e19446c694d9b @goatslacker committed Mar 20, 2013
Showing with 15 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +13 −3 index.js
  3. +1 −1 package.json
View
@@ -0,0 +1 @@
+node_modules
View
@@ -1,11 +1,17 @@
var getParameterNames = require('get-parameter-names')
-function DI() {
- this._registers = {}
+function DI(registers) {
+ this._registers = registers || {}
}
DI.prototype.register = function (name, fn) {
- this._registers[name] = fn
+ if (typeof name === 'object') {
+ Object.keys(name).forEach(function (key) {
+ this._registers[key] = name[key]
+ }.bind(this))
+ } else {
+ this._registers[name] = fn
+ }
}
DI.prototype.getParameterNames = getParameterNames
@@ -35,4 +41,8 @@ DI.prototype.inject = function (fn, additionalDependencies) {
}
}
+DI.prototype.clone = function () {
+ return new DI(this._registers)
+}
+
module.exports = DI
View
@@ -1,7 +1,7 @@
{
"name": "dependency-injector",
"author": "Josh Perez <josh@goatslacker.com>",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Dependency Injection via function arguments",
"repository": {

0 comments on commit c88d1e9

Please sign in to comment.