The example below works fine, however I am trying to make the handleArcs() function more universal (i.e. handleLayer() ).
My layerVar has an onEachFeature property, which applies the onEachArc method to each layer function. I want handleArcs() take the onEachArc() function as an argument, but it does not work, and when I pass it and check with typeof , the result is undefined . This is basically a simple passing function as an argument to another function, but in this case it does not work.
My first guess was that something was wrong with this context. But since typeof thisShouldBeAFunction returns undefined back, I'm not sure what the problem is.
Any guesses what might be causing the problem?
function onEachArc(feature, layer) { if (feature.properties) { layer.bindPopup("<b>" + feature.properties.linkstr + "</b> has speed " + feature.properties.speed + "."); } }; function handleArcs(data, layerVar, layerName, thisShouldBeAFunction) { alert(typeof thisShouldBeAFunction);
getData() calls the jQuery AJAX method to get data from the server:
function getData(url) { return $.ajax({ url : url, type: 'GET', error : function (xhr,status,error){alert("An error happened while loading a file: "+error+".")} }); }
source share