Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
24 | ;( function ( $, mw, undefined ) { |
||
25 | |||
26 | 'use strict'; |
||
27 | |||
28 | $( function () { |
||
29 | $( '#fileupload' ).fileupload( { |
||
30 | dataType: 'json', |
||
31 | dropZone: $( '#fileupload-dropzone' ), |
||
32 | |||
33 | add: function ( e, data ) { |
||
34 | |||
35 | var status = $( '<li>' ).text( data.files[ 0 ].name ); |
||
36 | $( '#fileupload-results' ).append( status ); |
||
37 | |||
38 | data.formData = { |
||
39 | format: 'json', |
||
40 | action: 'upload', |
||
41 | token: $( this ).fileupload( 'option', 'token' ), |
||
42 | ignorewarnings: 1, |
||
43 | filename: data.files[ 0 ].name |
||
44 | }; |
||
45 | |||
46 | data.submit() |
||
47 | .success( function ( result /*, textStatus, jqXHR */ ) { |
||
48 | |||
49 | if ( result.error != undefined ) { |
||
50 | |||
51 | status.text( status.text() + " ERROR: " + result.error.info ).addClass( 'ful-error' ); |
||
52 | |||
53 | } else { |
||
54 | var link = $( '<a>' ); |
||
55 | link |
||
56 | .attr( 'href', mw.Title.makeTitle( mw.config.get( 'wgNamespaceIds' ).file, result.upload.filename ).getUrl() ) |
||
57 | .text( result.upload.filename ); |
||
58 | |||
59 | status |
||
60 | .addClass( 'ful-success' ) |
||
61 | .text( ' OK' ) |
||
62 | .prepend( link ); |
||
63 | } |
||
64 | |||
65 | } ) |
||
66 | .error( function ( /* jqXHR, textStatus, errorThrown */ ) { |
||
67 | status.text( status.text() + " ERROR" ).addClass( 'ful-error' ); |
||
68 | } ); |
||
69 | |||
70 | } |
||
71 | } ); |
||
72 | |||
73 | $( document ).bind( 'drop dragover', function ( e ) { |
||
74 | e.preventDefault(); |
||
75 | } ); |
||
76 | } ); |
||
77 | |||
78 | }( jQuery, mediaWiki )); |
||
|
|||
79 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.