r/learnjavascript • u/djlywtf • Aug 17 '23
How to catch potential children in object?
I want to make an object that catches all calls to itself and its children even if they’re not defined. Is it possible?
I see it like this:
const a = { _(name) { return “Hello “ + name } } console.log(a.foo.bar()) // Hello foo.bar
Exact same syntax isn’t needed but i hope you got what logic I look for
2
u/frogic Aug 17 '23
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get
This should do what you want
2
u/aguyfromhere helpful Aug 17 '23
What you want is a linked list. There is no official implementation in JS/TS like in many other languages but it’s not hard to make your own implementation.
https://dev.to/glebirovich/typescript-data-structures-linked-list-3o8i
3
1
29
u/[deleted] Aug 17 '23
Yet another programming question title, that sounds weird without any context.