Вызов $ .get является асинхронным. Посмотрите поток управления так:
parseUrl("http://www.test.com")
$.get(..., function callback() { /* this is called asynchronously */ })
return "";
...
// sometime later the call to $.get will return, manipulate the
// newLink, but the call to parseUrl is long gone before this
callback();
Я думаю, что вы хотели сделать:
function parseUrl(link, whenDone) {
$.get(link, function () {
var newLink = "";
// Do your stuff ...
// then instead of return we´re calling the continuation *whenDone*
whenDone(newLink);
});
}
// Call it like this:
parseUrl("mylink.com", function (manipulatedLink) { /* ... what I want to do next ... */ });
Добро пожаловать в мир асинхронных спагетти:)