dtex / j5e

Framework for embedded devices using ECMA-419, the ECMAScript® embedded systems API specification, based on Johnny-Five's API
https://www.j5e.dev/
MIT License
64 stars 6 forks source link

coding style question - arguments versus rest parameters #58

Closed phoddie closed 4 years ago

phoddie commented 4 years ago

This is a question, not an issue.

These two lines took me a little while to decode:

emit(event) {
  const args = [].slice.call(arguments, 1);

With rest parameters, I think it can be rewritten as:

emit(event, ...args) {

It seems possible that this is an artifact from the Johnny-Five Node implementation. The rest version is almost surely more efficient in XS (and maybe V8 now too?). For j5e, do you intend to keep the original coding style or migrate forward where there are readability and/or runtime benefits? Either seems reasonable: I ask to be able to respect the project's style and goals.

dtex commented 4 years ago

You hit the nail on the head. This code dates back many years (before we had rest params in JS). This particular bit is not from J5, but I see we have some instances in J5 as well so I'll get those tracked down in both repos.

Thanks for pointing it out and thank you for spending time on this. I appreciate it very much.

phoddie commented 4 years ago

Happy to help. I'm learning a lot along the way. ;)

If I run into other code that appears historic, I'll make a note and pass them along.

dtex commented 4 years ago

Shouldn't have closed this. I have yet to make this change and I will forget if I don't leave it open.

dtex commented 4 years ago

This is done in J5e. The instances I was remembering from Johnny-Five have either already been replaced, or weren't suitable for this refactor.