[Javascript] Overriding function

Overriding a function lets you wrap a third-party method with your own logic while still invoking its original behavior.

Example code:

const unmountApp = app.unmount
installedApps.add(app)
app.unmount = function () {
  installedApps.delete(app)
  if (installedApps.size < 1) {
    pendingLocation = START_LOCATION_NORMALIZED
    removeHistoryListener && removeHistoryListener()
    removeHistoryListener = null
    currentRoute.value = START_LOCATION_NORMALIZED
    started = false
    ready = false
  }
  unmountApp()
}

 

posted @ 2025-07-15 13:50  Zhentiw  阅读(8)  评论(0)    收藏  举报