有可能知道函数是否使用空返回语句? [英] Is it possible to know if function uses empty return statement?

查看:92
本文介绍了有可能知道函数是否使用空返回语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以知道函数是否使用空的return语句而不使用return关键字?

Is it possible to know if a function uses an empty return statement versus simply not using the return keyword?

例如:

function noReturn(){ }
function useReturn(){ return; }

console.log( noReturn() );   // undefined
console.log( useReturn() );  // undefined

我知道所有关于WHEN和WHY的人会使用空的return语句,我只是想要要知道你是否可以判断是否返回; 是否使用了所有而不是返回语句。

I know all about WHEN and WHY one would use an empty return statement, I just want to know if you can tell if return; was used at all versus no return statement.

我假设它不可能,那没关系。如果有任何很酷的函数原型技巧我不知道,那将是甜蜜的。

I'm assuming that its not possible, and thats ok. If there was any cool Function prototype trick I didn't know of, that would be sweet.



编辑:不试图解决任何特定问题问题,除非一般的好奇心是一个问题。 :)


Not trying to solve any particular problem, unless general curiosity is a problem. :)

推荐答案

您无法区分这三个函数的返回值:

You cannot distinguish return values of these three functions:

function a() { }
function b() { return; }
function c() { return undefined; }

这篇关于有可能知道函数是否使用空返回语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆