Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sad to see it go #25

Open
d3x0r opened this issue Feb 18, 2024 · 0 comments
Open

Sad to see it go #25

d3x0r opened this issue Feb 18, 2024 · 0 comments

Comments

@d3x0r
Copy link

d3x0r commented Feb 18, 2024

I think this would have simplified something I was doing myself in extending classes. I only just stumbled on this @@species today.

I implemented something like this for extending a protocol wrapper around client-side websockets.

export class Protocol  {
   constructor() {
      this.#Protocol = Object.getPrototypeOf( this ).constructor;
      this.#Protocol.ws = null;  // allocate a static websocket in the final implementation.
   }
   connect( protocol ) {
      const ThisProtocol = this_.#Protocol; //Object.getPrototypeOf( this ).constructor;
      ThisProtocol.ws = new Websocket( ..., protocol );
   }
}

I used to have to get the type with the long expression Object.getPrototypeOf( this ).constructor but realized I could just keep that per instance of a new Protocol(), I think using @@species would have simplified that expression also.

The client protocol is expected to only use a single connection to the server; where the server would have lots of these all over.

Example from here: https://github.com/d3x0r/sack.vfs/blob/master/apps/http-ws/client-protocol.js

Well, if nothing else, this is an example of how to get around not having @@species?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant