Show HN: Dynamically generate JavaScript class methods at runtime

https://github.com/ramadis/vibe-class
by ramadis • 1 year ago
1 0 1 year ago

built a weird little library last friday night. it uses LLMs to auto-generate JavaScript class methods at runtime; no need to define the method ahead of time—just decorate your class, call whatever you want, and the model figures it out on the fly.

it uses `Proxy`s, and pipes the class definition and the call example to the LLM for it to generate a valid method.

here's a very lean example:

``` class User { constructor(email) { this.email = email; } }

const EnhancedUser = asVibeClass(User);

const user = new EnhancedUser('john@example.com');

const domain = await user.getEmailDomain();

console.log(domain); // example.com

```

of course it was not built for production use, but it was a fun exploration. would love to hear your thoughts!

Related Stories

Loading related stories...

Source preview

github.com