Argument placeholder
The following piece of code from the jQuery source caught my eye (line 7716 from the latest revision bit.ly/jqsource):
send: function( _, callback ) {
script = document.createElement( "script" );
script.async = "async";
// BLA BLA BLA
}
At no point is the named parameter _
used开发者_如何学运维. It seems this is to force callback
to be arguments[1]
instead of arguments[0]
. Why would that be useful?
It's merely a convention adopted to reference non-used parameters.
If they didn't have some parameter name there, the only way to get the second argument would be to do:
arguments[1];
...and that would bring us back to your earlier question about JSLint complaining about static reference to individual members of the arguments
object.
Looking at the source, depending on the result of jQuery.support.ajax
, jQuery.ajaxTransport
gets assigned one of two functions.
The first one you saw has this signature:
send: function( _, callback )
Which means the first argument is not used.
The second one on the other hand (search for send:
on the source), has this signature:
send: function( headers, complete )
In order to maintain a common interface for the send method, the first one has to accept the parameters even if they are not used.
BTW, the first one doesn't seem to use the headers
since it simulates a request using a <script/>
element.
精彩评论