Closed jhpratt closed 5 years ago
It's for bytes. There's a self.open
and because of that, the fat arrow reference expands to something slightly more verbose/repetitive.
You're right tho. Getting rid of self
entirely has been on my to-do list. I'm pretty sure can save another 5-10 bytes by doing so.
Also, just taking a look, wouldn't it be simpler to do something along the lines of self.send = ws.send
? As a bonus, you're getting whatever ws.send
returns, if that's even useful.
Unfortunately no because ws
is not definited initially and can be changed throughout the Sockette lifetime. The true ws
updates internally and that's why it lives within a function.
And moving self.send = ws.send
to inside open
presents issue to anyone who was saving a reference to send
in their app.
Aka
ctx = new Sockette(...)
let mySend = ctx.send;
// Doesn't exist
Closed via https://github.com/lukeed/sockette/compare/e2ffefd..c8c8d91
Saved 20 bytes 🎉 ...then 5102793e68881c1b588a8eb050c16ee1b77599c1 added 4 more 💩
Arrow functions don't create a binding, and a quick look over the code doesn't show a single instance where the difference in bindings would matter. Every instance of
this
can be replaced withself
.