concept instance in category jQuery

appears as: instce, instce, instces, n instance, The instce
jQuery UI in Action

This is an excerpt from Manning's book jQuery UI in Action.

You can view this example live at http://jsfiddle.net/tj_vantoll/Eda2W/. If you append /show to the end of a jsFiddle URL (for instance, http://jsfiddle.net/tj_vantoll/Eda2W/show/), you can view the example outside of the jsFiddle UI—it’s the equivalent of looking at just the Result pane. Finally, if you create a jsFiddle account, you can use http://jsfiddle.net/draft/ to view the result of last example you ran. Because the draft URL is short (and bookmarkable), it’s handy for testing on mobile devices.

Figure 12.6. Visualization of the JavaScript interpreter accessing a property or method on an instance. The first example looks for an element property and immediately finds it on the instance object. The second example looks for a destroy() method and has to go through the instance object, the custom widget’s prototype, and the dialog widget’s prototype, before finding the method on the base widget’s prototype.

Every time you instantiate a widget on a DOM element, the widget factory creates an object—the instance—and associates it with the element using $.data(). The key used to store the instance on the element is the widget’s full name—that is, the widget’s namespace, plus a dash, plus the widget’s name. The dialog widget is stored under a key of "ui-dialog" because its namespace is "ui" and its name is "dialog".

You can retrieve the instance a few ways. The first is to use $.data(), as shown in the following code, which assigns the instance of a newly created dialog to a variable (named instance):

var myDialog = $( "<div>" ).dialog(),
    instance = myDialog.data( "ui-dialog" );

As of jQuery UI 1.11, you can also retrieve the instance using the widget’s instance() method. The following code assigns a newly created dialog instance to an instance variable:

var myDialog = $( "<div>" ).dialog(),
    instance = myDialog.dialog( "instance" );

The instance() method is the preferred means of accessing the instance as it doesn’t rely on the jQuery UI internal implementation (storing the instance using $.data()). But regardless of how you access the instance, what might you want to do with it?