When encapsulating some general methods, it is better to add more methods or to distinguish them by configuration.

is it better to add more methods or pass parameters when encapsulating some general methods?
for example, I re-encapsulate the ajax of jq.
the first method is as follows. The request method is put in the parameters. For example, type can be post or GET

.
request({
    type:POST,
    url:xxxx,
    data:{}
})

the second method is as follows, and a separate method is added

request.get({
    url:xxxx,
    data:{}
})

  request.post({
    url:xxxx,
    data:{}
})

the above is a simple example, which is roughly what it means. Which of these two methods is better?

Mar.18,2021

the second method is more intuitive and readable, but it does not have good expansibility. Look at your own business requirements, such as ajax method, there are only a few, and there will be no more, so I think the second method is better


this is not necessarily, it depends on the specific situation of method use and definition.
is more about implementation conventions.

Menu