jquery / jquery/learn.jquery.com

Syntax for getting "options" values from $.widget( "ns.plugin"

Open
#741 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Chapter: jquery-ui
Dominant language
JavaScript
Stars
915
Forks
471
PR merge metrics
No merged PRs in 30d

Description

On the "Why Use the Widget Factory?" page, https://learn.jquery.com/jquery-ui/widget-factory/why-use-the-widget-factory/, the last example, what is the correct way to get the value of each "option"?

   $.widget( "ns.plugin", { 
       // Default options.
       options: {
           param1: "foo",
           param2: "bar",
           param3: "baz"
       },

       _create: function() {
           // Options are already merged and stored in this.options
           // Plugin logic goes here.
       } 
   });

Using this.options.param1 will get the correct value for this one entry, but a user should be able to get all of the values in options like an array.

Using the following code:

  $.each(this.options, function(key, value) {
     alert(key + ":" + value);
  });

returns:

  • classes:[object Object]
  • disabled:false
  • create:null
  • param1:foo
  • param2:bar
  • param3:baz

I expect the last 3 output, but not the first 3.

What is the proper syntax to just get:

  • param1:foo
  • param2:bar
  • param3:baz

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the “Why Use the Widget Factory?” page linked in the issue and review its final $.widget("ns.plugin") example. Determine how the example should distinguish the plugin's declared options from other option values, then update the page so the expected param1, param2, and param3 output and correct syntax are clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.