"exit" 方法从何而来?它在哪里记录?

Where does the "exit" method come from? Where is it documented?

我一直在关注 walkthrough tutorial on Step 19: Reuse Dialogs. In the code below, I cannot figure out where the exit method comes from. I could not find anything in the API reference for ManagedObject

sap.ui.define([
  "sap/ui/base/ManagedObject",
  "sap/ui/core/Fragment"
], function (ManagedObject, Fragment) {
  "use strict";

  return ManagedObject.extend("sap.ui.demo.walkthrough.controller.HelloDialog", {
    constructor: function(oView) {
      this._oView = oView;
    },
    exit: function () {
      delete this._oView;
    },
    open: function() {
      // ...
    }
  });
});

如果 API 参考文献中没有记录,有人怎么知道 exit 可以覆盖,更重要的是,为什么不覆盖 destroy 而不是 exit?类似于:

  // ...
  return ManagedObject.extend("sap.ui.demo.walkthrough.controller.HelloDialog", {
    constructor: function(oView) {
      this._oView = oView;
    },
    destroy: function() {
      delete this._oView;
      ManagedObject.prototype.destroy.apply(this, arguments);
    },
    open: function() {
      // ...
    }
  });
});

挂钩方法 exit 记录在 ManagedObject 的 subclass sap.ui.core.Element: https://openui5.hana.ondemand.com/api/sap.ui.core.Element#methods/exit

Hook method for cleaning up the element instance before destruction. Applications must not call this hook method directly, it is called by the framework when the element is destroyed.
Subclasses of Element should override this hook to implement any necessary cleanup.

exit: function() {
   // ... do any further cleanups of your subclass e.g. detach events...

   if (Element.prototype.exit) {
       Element.prototype.exit.apply(this, arguments);
   }
}

For a more detailed description how to to use the exit hook, see Section exit() Method in the documentation.

sap.ui.base.Object > .EventProvider > .ManagedObject > sap.ui.core.Element > .Control > ...


“为什么不改写 destroy?”好吧,演练没有解释的一件事是,在开发 UI5 内容时主要有 两个 角色:

  • Control-/ framework-为应用开发提供平台的开发者
    → 覆盖 protected 方法,例如 exit.
  • 应用程序 纯粹使用高级控件和 API 的开发人员。
    → 应该只调用 public 方法,例如 destroy 如果不再需要控件。

在第 19 步中,通过扩展 low-level class(例如 ManagedObject),您将跨越应用程序开发人员角色并提供 hook 方法,适用于将调用 myHelloDialog.destroy().

的应用程序开发人员