I am using a YUI Tooltip to show an error message when users mouse over an error icon displayed next to a form field. When the error goes away, I remove the alert icon from the DOM, and want to remove the tooltip as well. For this I call tooltip.destroy()
. Is it the right way to do this, or is the destroy()
intended for something else? The documentation for destroy()
is not extremely clear on the subject.
(I am asking the question because if you开发者_StackOverflow destroy the tooltip right after doHide()
was called on the tooltip, hide()
is called 5 s later, which gives you an error as hide()
tries to access this.cfg which has been set to null by destroy()
. This might be a YUI bug, or as I suspect, as sign that I am not using the API the way it was intended.)
Instead of doing tooltip.destroy()
, it seems better to disabled the tooltip. It might not be as memory efficient as destroying the tooltip, but it avoids the issue mentioned in the question where callbacks registered before the call to destroy()
but running afterwards have a hard time dealing with properties of the object being null
. Also, if the tooltip might be showing, you'll want to hide it right away by calling hide()
. In summary, the code will be:
tooltip.cfg.setProperty("disabled", true);
tooltip.hide();
精彩评论