robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
8.01k stars 584 forks source link

Add Console type #494

Closed fabiante closed 1 year ago

fabiante commented 1 year ago

This PR is a draft inspired by the existing PR #445. My goal is to contribute allow users of otto to pass in their own implementation of a new Console interface for two reasons:

For now this is a draft because I need feedback by more experienced maintainers. I will update the PR description once the option of merging is given. I am happy with merging only some refactorings or submitting them step-wise in smaller PRs if that is of any help.

Closes: https://github.com/FabianTe/otto/issues/1

fabiante commented 1 year ago

Mind having a look at my take at making the general system arround console more flexible? @stevenh

FYI @andig

chrislowth commented 1 year ago

Have you considered adding the features you want for your project using the standard otto API?

You don't need to update otto itself to do this.

fabiante commented 1 year ago

Have you considered adding the features you want for your project using the standard otto API?

Yes, I have and in fact am already doing that. I plan to build a couple of "extensions" which I'd like to open source once I they are usable.

I agree that adding more features to otto just increases the projects size. For console I think differently: The builtin console logs to stdout which is a side effect I don't want in my application. AFAIK there is no option to change and disable that, therefore I wanted to contribute something. LMT if i massively missed the target :)

fabiante commented 1 year ago

Closing as I have established overwriting / reseting the console object in a custom factory function. The main project probably does not need more abstractions arround this

IMO it should still be possible to not have the console object as it has side effects which I would assume most people don't want.