JavaScript - 从匿名函数返回(varScope) [英] JavaScript - Return from anonymous function (varScope)
本文介绍了JavaScript - 从匿名函数返回(varScope)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<script>
var sample = function() {
(function() {
return "something"
})();
// how can I return it here again?
}
</script>
有没有办法再次从父函数中的匿名函数返回返回值,或者我是否需要使用定义的函数来获取返回值?谢谢!:)
Is there a way to return the returned value from the anonymous function in the parent function again or do I need to use a defined function to get the returned value? Thanks! :)
推荐答案
只需将 return 语句放在调用函数的位置即可.
Just put the return statement at the point where you call the function.
<script>
var sample = function() {
return (function() { // The function returns when you call it
return "something"
})();
}
</script>
这篇关于JavaScript - 从匿名函数返回(varScope)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文