How to understand success and fail, in functions I remember that even anonymous functions need to be called in parentheses.

export const geocoder = (lat, lon, success = () => {}, fail = () => {}) => {
  return wx.request({
    url: "https://apis.map.qq.com/ws/geocoder/v1/",
    data: {
      location: `${lat},${lon}`,
      key: QQ_MAP_KEY,
      get_poi: 0
    },
    success,
    fail
  })
}
May.24,2021

this is the object literal abbreviation of ES6 . will automatically help you complete the assignment of key values
ES6

.
wx.request({
    success,
    fail
  })

equals ES5

wx.request({
    success: success,
    fail: fail
  })

your geocoder is a function, success and fail are just the parameters you pass, the default value of the parameter is a function, and the success and fail here are just function parameters


this is the abbreviation of the literal quantity of objects in ES6. It is recommended that you take a look at this

.
Menu