What do you think about a C# 6 like nameof() expression for JavaScript.

Behrang Saeedzadeh behrangsa at gmail.com
Sun Aug 9 01:27:09 UTC 2015


Forgot to mention that nameof works with local variables too:

function foo() {
 var aNum = 1;
 console.log(nameof(aNmum), aNum);
}


On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh <behrangsa at gmail.com>
wrote:

> So basically we could use it like this:
>
>
> function aFunc(aParam) {
>     throw new Error(nameof(aParam));
> }
>
>
> and nameof(aParam) would return the string "aParam".
>
>
> This is possible to do even right now using arguments.callee and some
> hacky code, but having it built-in to spec would be nicer IMHO.
> --
> Best regards,
> Behrang Saeedzadeh
>
-- 
Best regards,
Behrang Saeedzadeh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150809/52942cfc/attachment.html>


More information about the es-discuss mailing list