How to leave this generic javascript function [closed]

3

I have this function below and would like to leave it generic, since the values of innermap , -125,127 and 3 will vary.

Instead of creating multiple functions: centralizar() ; centralizar1() ; etc., I would like to leave only one function and only pass the parameters to the next functions where the values will be different.

How to do this?

function centralizar() {
    innermap.flyTo([-125,127], 3);
}
    
asked by anonymous 24.11.2017 / 15:50

1 answer

9

Using parameters

function centralizar(innermap, a, b, c) {
  innermap.flyTo([a, b], c);
}

Or maybe use an array instead of b, c . Kicking the parameters are coordinates and zoom , would be

function centralizar(map, coords, zoom) {
  innerMap.flyTo(map, coords, zoom);
}

bfavaretto's tip in comments.

Function documentation

    
24.11.2017 / 15:52