我不能從功能獲得燙髮! 這裏存在範圍問題JavaScript範圍,燙髮不能得到正確的變量
var perm = "none";
var participantsPromise = getChannelParticipants(peerID * -1).then(
function (participants) {
angular.forEach(participants, function (participant){
if (participant.user_id == UserID) {
switch (participant._) {
case "channelParticipant":
perm = "normal";
console.log('->>>>>>> Perm = normal');
break;
case "channelParticipantEditor":
perm = "Admin";
console.log('->>>>>>> Perm = Admin');
break;
case "channelParticipantModerator":
perm = "Admin";
console.log('->>>>>>> Perm = Admin');
break;
case "channelParticipantCreator":
perm = "Creator";
console.log('->>>>>>> Perm = Creator');
break;
default:
console.log('#########> No handler for', participant._);
perm = "unknown";
}
}
})
});
return perm;
函數返回無,但燙髮已經設置其他值。 我能做什麼?
請參閱[我的回答(http://stackoverflow.com/a/39742108/2545680) –