3 ms·
This antipattern is taken to the extreme with the `DOMParser` [1] class in the Browser. The constructor takes no arguments and it has a single instance method
by DarkWiiPlayer 6y ago
This antipattern is taken to the extreme with the `DOMParser` [1] class in the Browser.
The constructor takes no arguments and it has a single instance method that takes produces a result without mutating any internal state.
What's worse, the method returns a newly created object of another class, which in my head is an indication that maybe, just MAYBE it should have been a constructor of said other class instead.
[1] https://developer.mozilla.org/en-US/docs/Web/API/DOMParser https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
- chrisoverzero 6y agoAs it says in the HTML Standard[0]: >The design of `DOMParser`, as a class that needs to be constructed and then have its `parseFromString()` method called, is an unfortunate historical artifact. If we were designing this functionality today it would be a standalone function. [0]: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization https://html.spec.whatwg.org/multipage/dynamic-markup-insert...
- Tomis02 6y ago> The design of `DOMParser` ... is an unfortunate historical artifact My prediction is that in 20-30 years the same will be said about today's mainstream OOP.
- richthegeek 6y agoThe browser could be seen as a special case, as it's the most public API around. So classes are in many cases simply for namespacing and modularisation. Interestingly, the HTML spec for DOMParser has a note about exactly your comment: https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#domparser https://html.spec.whatwg.org/multipage/dynamic-markup-insert... (scroll up 2 lines)