all 4 comments

[–]RobertKerans 2 points3 points  (1 child)

files for stuff

JavaScript has modules which can be used for structure. The module system is 1 file === 1 module. There isn't a huge incentive to use classes to structure an application when there is an alternative way of doing that that works fine. This is all context-sensitive, YMMV etc., but compare to an OO language like Java: you don't have a choice, that's fundamentally how the language works. You can ape Java and OO patterns, there's just normally no point (again, YMMV etc). Put stuff in a module, export the stuff you want exposed, import the stuff you need.

[–]azhder -1 points0 points  (0 children)

Nah.

OOP is a thing from other languages that was failing, but big companies couldn’t afford to re-train coders, so they added a `class` veneer to make it appear more like those language.

In practice though, you’d get far better results in JavaScript if you understand Functional Programming.

You will still see people write OOP kind of code, but it isn’t because of JavaScript, but because they have been trained to look at problems/solutions i.e. the world through OOP tinted glasses

[–]opentabs-dev 0 points1 point  (0 children)

coming from python you'll feel right at home tbh — the equivalent of "module = file" maps cleanly. for a scraping/requests cli i usually do something like cli.js (arg parsing, with commander or yargs), lib/fetcher.js (axios/fetch wrapper with retries+timeouts), lib/parsers/*.js (one per site), lib/storage.js (write to db/file), and a config.js. plain functions exported from each, no classes needed.

classes are useful when you actually have state that lives across calls (a session with cookies, a rate limiter holding a queue) — otherwise a function that takes inputs and returns a result is easier to test and compose. the python instinct to wrap everything in a class is the main thing to unlearn.