Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I regularly add Symbol based features to JS libraries I'm using (named methods are riskier, of course)

    import { SomeStreamClass as SomeStreamClass_ } from "some/library"
    export class SomeStreamClass extends SomeStreamClass_ {
      [someSymbol] (...) { ... }
      ...
    }
I have not blown my foot off yet with this approach but, uh, no warranty, express or implied.

It's been working excellently for me so far though.



Much nicer than just adding your symbol method to the original class. :p


13 days late but for posterity:

Yes. Not Wanting To Do That was the motivating factor for coming up with this approach :D


I guess it could be improved with a simple check if SomeStreamClass_ already has someSymbol and then raise an exception, log a warning or some such.


8 days late but for posterity:

So far I've only ever been using a private symbol that only exists within the codebase in question (and is then exported to other parts of said codebase as required).

If I ever decide to generalise the approach a bit, I'll hopefully remember to do precisely what you describe.

Possibly with the addition of providing an "I am overriding this deliberately" flag that blows up if it doesn't already have said symbol.

But for the moment, the maximally dumbass approach in my original post is DTRT for me so far.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: