Skip to content

Clarify that many of the widget methods return undefined through instanc... #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions page/jquery-ui/widget-factory/widget-method-invocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This returns the value of the [dialog's `height` option](http://api.jqueryui.com

### Instance Invocation

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.
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.

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

### Return Types

Most methods invoked through the widget's plugin will return a `jQuery` object so the method call can be chained with additional jQuery methods.
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 even of methods that return `undefined` when invoked on the instance. This is shown in the example below.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"even true even"


```
$( ".selector" )
.dialog( "close" )
var dialog = $( ".selector" ).dialog();

// Instance invocation - returns undefined
dialog.data( "ui-dialog" ).close();

// Plugin invocation - returns a jQuery object
dialog.dialog( "close" );

// Therefore, plugin method invocation makes it possible to
// chain method calls with other jQuery functions
dialog.dialog( "close" )
.css( "color", "red" );
```

Expand Down