Skip to content

Commit 8cc59c2

Browse files
committed
Clarify that many of the widget methods return undefined through instance invocation.
1 parent 7311bdd commit 8cc59c2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

page/jquery-ui/widget-factory/widget-method-invocation.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This returns the value of the [dialog's `height` option](http://api.jqueryui.com
2323

2424
### Instance Invocation
2525

26-
Under the hoods, every instance of every widget is stored on the element using [`jQuery.data()`](http://api.jquery.com/jQuery.data/). To retrieve the instance object, call `jQuery.data()` using the widget's full name as the key. Let's look at each.
26+
Under the hoods, every instance of every widget is stored on the element using [`jQuery.data()`](http://api.jquery.com/jQuery.data/). To retrieve the instance object, call `jQuery.data()` using the widget's full name as the key. This is shown below.
2727

2828
```
2929
var dialog = $( ".selector" ).data( "ui-dialog" );
@@ -44,11 +44,20 @@ $( ".selector" ).dialog( "instance" ).close();
4444

4545
### Return Types
4646

47-
Most methods invoked through the widget's plugin will return a `jQuery` object so the method call can be chained with additional jQuery methods.
47+
Most methods invoked through the widget's plugin will return a `jQuery` object so the method call can be chained with additional jQuery methods. This is even true of methods that return `undefined` when invoked on the instance. This is shown in the example below.
4848

4949
```
50-
$( ".selector" )
51-
.dialog( "close" )
50+
var dialog = $( ".selector" ).dialog();
51+
52+
// Instance invocation - returns undefined
53+
dialog.data( "ui-dialog" ).close();
54+
55+
// Plugin invocation - returns a jQuery object
56+
dialog.dialog( "close" );
57+
58+
// Therefore, plugin method invocation makes it possible to
59+
// chain method calls with other jQuery functions
60+
dialog.dialog( "close" )
5261
.css( "color", "red" );
5362
```
5463

0 commit comments

Comments
 (0)