Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this?
```js function foo(x) { return nameof(x); } foo(bar); // "bar"; ``` In that case, the engine would have to keep track of usages as well, in a similar sense as `arguments.callee`, and if it were a function, it would make optimization quite difficult, as engines don't have the capacity to statically analyze that such a function is used. If it is like `typeof`, we now have a breaking change - a keyword that was a valid Identifier before. ```js // Error? function nameof(value) { return value.name; } var bar = {name: 2}; nameof(bar); // "bar" or 2? ``` I don't think this is going to work out in practice, not in ECMAScript proper. You might appreciate Sweet.js, though. On Sat, Aug 8, 2015, 21:27 Behrang Saeedzadeh <behran...@gmail.com> wrote: > 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 <behran...@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 > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss