RSG-Group / hyper-background

Easily change the background of your Hyper terminal!
https://npmjs.com/package/hyper-background
Apache License 2.0
9 stars 3 forks source link

Object mutation "bug" #1

Closed Nicholaiii closed 7 years ago

Nicholaiii commented 7 years ago

Referring to: https://github.com/RSG-Group/hyper-background/blob/4dea139affa8ed0b108219a6f35c415acc564aed/src/index.ts#L12-L13

I know this is very trivial, but I just wanted to let you know, that if you actually wanted to avoid mutation you should use a clone or assign method. In your case, the object is passed by reference and will mutate (iow have side-effects) when you change it. Here's an example that shows.

retrixe commented 7 years ago

Yes, you can do that, I just did that to shut ESLint up :joy: Hyper doesn't have any specific problem with mutation I am aware of, and I am aware it is simply a reference. The comment is slightly confusing, I admit :stuck_out_tongue:

Anyways, yes, we can use Object.prototype.assign/JSON.parse(JSON.stringify(object)) but there's not much use, as we simply end up creating a new object and use a couple more bytes of RAM than a simple pointer. Extremely trivial difference, because we don't have an issue with mutating the arguments, really.

Also, since the change to Standard code style, it seems it doesn't mind mutation of arguments, which Airbnb does mind. So the reference pointer will be removed.

Thanks @Nicholaiii!