Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 | ;(function( window, document, undefined ) { |
||
|
|||
2 | "use strict"; |
||
3 | |||
4 | var Plugin = function( selector, options, markerOptions ) |
||
5 | { |
||
6 | this.el = castor._isString( selector ) ? document.querySelector( selector ) : selector; |
||
7 | if( this.el ) { |
||
8 | this.options = castor._extend( this.defaults, options, this.el.getAttribute( 'data-map-options' )); |
||
9 | this.init( markerOptions ); |
||
10 | } |
||
11 | } |
||
12 | |||
13 | Plugin.prototype = |
||
14 | { |
||
15 | defaults: { |
||
16 | center: { lat:0, lng:0 }, |
||
17 | disableDoubleClickZoom: true, |
||
18 | draggable: true, |
||
19 | fullscreenControl: false, |
||
20 | mapTypeControl: false, |
||
21 | // mapTypeId: google.maps.MapTypeId.ROADMAP, |
||
22 | overviewMapControl: false, |
||
23 | rotateControl: false, |
||
24 | scaleControl: false, |
||
25 | scrollwheel: false, |
||
26 | streetViewControl: false, |
||
27 | styles: [], |
||
28 | zoom: 16, |
||
29 | zoomControl: true, |
||
30 | }, |
||
31 | |||
32 | init: function( markerOptions ) |
||
33 | { |
||
34 | this.map = new google.maps.Map( this.el, this.options ); |
||
35 | |||
36 | this.markerOptions = castor._extend({ |
||
37 | position: this.options.center, |
||
38 | animation: google.maps.Animation.DROP, |
||
39 | }, markerOptions, this.el.getAttribute( 'data-marker-options' ), { map: this.map }); |
||
40 | |||
41 | this.marker = new google.maps.Marker( this.markerOptions ); |
||
42 | |||
43 | google.maps.event.addDomListener( window, 'resize', this.onResize.bind( this )); |
||
44 | }, |
||
45 | |||
46 | onResize: function() |
||
47 | { |
||
48 | (new AnimationFrame()).request( function() { |
||
49 | this.map.setCenter( this.marker.getPosition() ); |
||
50 | }.bind( this )); |
||
51 | }, |
||
52 | }; |
||
53 | |||
54 | Plugin.defaults = Plugin.prototype.defaults; |
||
55 | |||
56 | castor.GoogleMaps = Plugin; |
||
57 | |||
58 | })( window, document ); |
||
59 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.