I'm trying to return a value from a method. I have a nested function within the method which should return a value.
However, I can't seem to get it to return the value of title when calling traverseProjects()
.
Here's my code.
getTitle: function(userId, projectId) {
u = new Firebase('<firebase.com>/users/' + userId + /projects/ + projectId);
function traverseProjects() {
u.once('value', function(snapshot) {
if (snapshot.key() === projectId) {
var obj = snapshot.val();
var title = obj.details.title;
}
console.log(title);
return title;
});
}
var title = traverseProjects();
console.log(title);
return title;
}