What is params and what does it do?

I am currently working through Learning jQuery 4th edition, where I am given an example of a form that takes a single text input. The form, when submitted, looks at jQuery documents for the entered string, extracts it as a JSONP object, and displays it.

In this example, I am provided with the following code snippet

//more code var buildItem = function(item) { var title = item.name, args = [], output = '<li>'; if (item.type == 'method' || !item.type) { if (item.signatures[0].params) { $.each(item.signatures[0].params, function(index, val) { args.push(val.name); }); } title = (/^jQuery|deferred/).test(title) ? title : '.' + title; title += '(' + args.join(', ') + ')'; } else if (item.type == 'selector') { title += ' selector'; } output += '<h3><a href="' + item.url + '">' + title + '</a></h3>'; output += '<div>' + item.desc + '</div>'; output += '</li>'; return output; }; //more code 

I'm having trouble understanding the string

  $.each(item.signatures[0].params, function(index, val) { args.push(val.name); }); 

in particular, what does .params actually do? I understand that it accesses files from within the signature in the returned object, but I do not see any .params in the returned object, and I cannot find any documentation for the .params ..

Any help would be appreciated.

jsFiddle can be found here: http://jsfiddle.net/QPR4Z/2/

-one
javascript jquery
source share
1 answer

See the value in signatures[0] - note that this is arbitrary data from a JSON request [for jQuery API documentation]. That is, ".params" does nothing but the usual function of accessing properties. Despite the syntax highlighting, this is not a reserved word and has no special meaning.


Below is some highlighted JSON to illustrate this point:

 "signatures":[ { // <-- ie signatures[0] "added":"1.8", "params":[ // <-- property called "params", which represents an array // of objects that describe the given parameter {"name":"selector","type":"Selector",..} ], .. }, .. ] 
+2
source share

All Articles