I am creating a variable where its value is determined by a particular method. This particular method should return an object with two properties. However, after the method returns the variable is undefined. I check the objects value right before it's returned and its fine. So there is something happening between the return and instantiate of the variable that causes it to be undefined. Here is a code snippet:
var results = findTarget(target, after, append); //undefined
function findTarget(target, after, append){
var currenttemplate = $(target).attr('data-template');
for(var i=0; i<after.length; i++){
if(after[i] === currenttemplate)
return {target : target, drop : "after"};
}
for(var j=0; j<append.length; j++){
if(append[j] === currenttemplate){
var obj = {target : target, drop : "append"};
console.log(obj); //is fine here
return obj; //this gets returned
}
}
if(currenttemplate === threshold) {
return "";
}
findTarget($(target).parent()[0], after, append);
}