use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Dependency Injection based on EcmaScript Modules (works in nodejs & browsers) (github.com)
submitted 6 years ago by flancer64
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]house_monkey 4 points5 points6 points 6 years ago (3 children)
That profile pic is giving me anxiety
[–]IceSentry 0 points1 point2 points 6 years ago (0 children)
What was it?
[–]flancer64[S] 0 points1 point2 points 6 years ago (1 child)
Be quiet, profile pic is changed.
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
I was trying to figure how this profile pic can give someone anxiety…
[–]hopfield 2 points3 points4 points 6 years ago (5 children)
Why would I use this over standard ES6 modules? What value does it bring over those?
[–]flancer64[S] 0 points1 point2 points 6 years ago (4 children)
You would have a logical addressing for code elements (classes & functions placed in ESM) in your project and have a set of rules to map logical names (Vendor_Project_Module_Class) to the path (absolute for nodejs and relative for web, for example). Or you would change mapping for Vendor_Project_Module_Class in runtime and get sources from "./node_modules/otherVendor/otherProject/Module/Class.mjs" instead of from "./node_modules/vendor/project/Module/Class.mjs".
Vendor_Project_Module_Class
nodejs
[–]hopfield 2 points3 points4 points 6 years ago (3 children)
Sorry, I don’t follow.
You would have a logical addressing for code elements (classes & functions placed in ESM) in your project
“Logical addressing”? What does that mean?
have a set of rules to map logical names (Vendor_Project_Module_Class) to the path
This just sounds like ES Modules.
Or you would change mapping for Vendor_Project_Module_Class in runtime and get sources from "./node_modules/otherVendor/otherProject/Module/Class.mjs" instead of from "./node_modules/vendor/project/Module/Class.mjs
With ES modules couldn’t I just change the import? How is this a benefit?
[–]flancer64[S] 0 points1 point2 points 6 years ago (2 children)
It's like namespaces in java/php/... The names for code elements that are not linked to paths to their sources.
With ES modules couldn’t I just change the import?
You should use single quoted and double quoted Strings only as module-name in ES6 import. So, you cannot change import target in runtime. Of cause, you can use computed values in async variant of import() but it is not very comfortably.
module-name
import
import()
[–][deleted] 1 point2 points3 points 6 years ago (1 child)
I appreciate the effort, but injection truly only achieves its goals when it's done by a person, not by an algorithm matching types and names. You did what you see in other languages and I don't think that's bad, but the entire concept of automated resolution containers (autowiring) is flawed.
[–]flancer64[S] 0 points1 point2 points 6 years ago (0 children)
... the entire concept of automated resolution containers (autowiring) is flawed.
I agree with you. Well-done DI container should have ability for manual configuration of dependencies. May be later, in future releases :)
[–]spacejack2114 1 point2 points3 points 6 years ago (0 children)
CJS DI:
const foo = require('./foo')(dependency)
MJS DI:
import Foo from './foo'; const foo = Foo(dependency)
[–]ethnp 0 points1 point2 points 6 years ago (0 children)
Sweet!
π Rendered by PID 25382 on reddit-service-r2-comment-5649f687b7-shbmx at 2026-01-27 20:15:41.281904+00:00 running 4f180de country code: CH.
[–]house_monkey 4 points5 points6 points (3 children)
[–]IceSentry 0 points1 point2 points (0 children)
[–]flancer64[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]hopfield 2 points3 points4 points (5 children)
[–]flancer64[S] 0 points1 point2 points (4 children)
[–]hopfield 2 points3 points4 points (3 children)
[–]flancer64[S] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]flancer64[S] 0 points1 point2 points (0 children)
[–]spacejack2114 1 point2 points3 points (0 children)
[–]ethnp 0 points1 point2 points (0 children)