DEV Community

Discussion on: Fetch - from simple to scalable implementation

Collapse
proto133 profile image
Peter Roto

Thanks for the article, it was interesting.

As a newer Dev, I have a question that probably any one could answer, but could you have made fetcher a constructor function so thoughout the code you could simply call like fetcher.get(arguments, options, etc)?

If so, would you ever do this? If not, why wouldn't it work?

Collapse
nombrekeff profile image
Keff Author

Hey, peter! I'm glad you liked it

I don't know If I understand the question correctly, I will answer what I think you meant, but please let me know if it wasn't this, I'm happy to resolve any questions you have!

Do you mean creating a fetcher object using a constructor function (class) instead, something like this:

class Fetcher {
   get(uri, options) {
     ...
   }
}

const fetcher = new Fetcher();
fetcher.get();
Enter fullscreen mode Exit fullscreen mode

If so, the answer is yes, you can do it in many ways, depending on many factors, like the codebase you already have, do you follow any practice that forces you to do it one way or another, etc...

I'm currently working on a post similar to this one but in an object-oriented approach. In this example, I stuck to functions to make it clearer, as OOP has more code and is a bit more difficult to follow!

I will let you know when I post it so you can see the different approach.

Collapse
proto133 profile image
Peter Roto

This answered my question. Thank you so much for your reply.