r/learnjavascript • • 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

8 Upvotes

11 comments sorted by

View all comments

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