From ee7679178d37dbf48c6465f8a035b70460eb2089 Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Wed, 22 Nov 2023 15:20:58 +0100 Subject: [PATCH] chore: internally document methods --- lib/injector.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/injector.js b/lib/injector.js index 0a7eaae..fe254cb 100644 --- a/lib/injector.js +++ b/lib/injector.js @@ -114,11 +114,20 @@ export default function Injector(modules, parent) { }; } - function instantiate(Type) { + /** + * Instantiate the given type, injecting dependencies. + * + * @template T + * + * @param { Function | [...string[], Function ]} type + * + * @return T + */ + function instantiate(type) { const { fn, dependencies - } = fnDef(Type); + } = fnDef(type); // instantiate var args constructor const Constructor = Function.prototype.bind.apply(fn, [ null ].concat(dependencies)); @@ -126,6 +135,17 @@ export default function Injector(modules, parent) { return new Constructor(); } + /** + * Invoke the given function, injecting dependencies. Return the result. + * + * @template T + * + * @param { Function | [...string[], Function ]} func + * @param { Object } [context] + * @param { Object } [locals] + * + * @return {T} invocation result + */ function invoke(func, context, locals) { const { fn,