RE: What do you think about a C# 6 like nameof() expression for JavaScript.
While its true most IDE's can search for references in strings, `nameof` takes some of the guesswork out of determining whether a substring that matches a symbol refers to the symbol or is merely part of the sentence. That said, `nameof` is primarily a convenience for an IDE. Ron Sent from my Windows Phone From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: 8/8/2015 8:57 PM To: Ron Bucktonmailto:ron.buck...@microsoft.com; Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. To be honest, most larger IDEs also search for references in strings, and even if it doesn't, any decent editor can do a regex replace of `identifierName` without problem. I don't see much of a problem here. Also, do you know of any other language that has this at the syntax level (not macro)? On Sat, Aug 8, 2015, 23:12 Ron Buckton ron.buck...@microsoft.commailto:ron.buck...@microsoft.com wrote: One of the main purposes of the `nameof` operator is to provide the string value of a symbol, so that if you perform a Rename refactoring of that symbol that the change is also reflected. This is primarily for cases where you perform precondition assertions tied to an argument: ``` ... static void Method(string x) { if (x == null) throw new ArgumentNullException(nameof(x)); ... } ``` Now, if I later rename `x`, I don't need to also find any string literals of x and manually update them. There are other uses of `nameof`, but they all boil down to roughly the same thing. Ron From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: 8/8/2015 7:23 PM To: Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. 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.namehttps://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fvalue.namedata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=pwV45avF9RX6COETpoLIY4EF%2bmCVmk6kEEmLc2JXSCY%3d; } 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.commailto: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.commailto: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.orgmailto:es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discusshttps://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fmail.mozilla.org%2flistinfo%2fes-discussdata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=7DHMx5gTd2OexSlKscSrKlMIxABMUkOKRC%2fuCbc6pWk%3d ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Question about [[Enumerate]] and property decision timing
Hi forks, Recently, we implemented Reflect.enumerate in WebKit JSC. At that time, the question is raised When are the enumerated keys determined?[1] For example, var object = ...; var iterator = Reflect.enumerate(object); object.newKey = hello; // At that time, iterator.next() is not called yet. for (var key of iterator) { print(key); // Here, newKey should be produced or not? } Seeing the spec, I think it's a little bit ambiguous. (correct?) In the current WebKit implementation, keys are cached when the iterator is created. Does this violate the spec behavior, The iterator’s next method processes object properties to determine whether the property key should be returned as an iterator value. ? Or, is it implementation dependent because If new properties are added to the target object during enumeration, the newly added properties are not guaranteed to be processed in the active enumeration.? And is the creation of the iterator by calling [[Enumerate]] included in active enumeration? [1]: https://bugs.webkit.org/show_bug.cgi?id=147677 Best regards, Yusuke Suzuki ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: please add orEqual operator
I was going to suggest a Set, now that ECMA has them… http://www.ecma-international.org/ecma-262/6.0/index.html#sec-set-objects ```js if ((new Set([1,2,3,5]).has(a)) { // stuff } ``` On Sun, Aug 9, 2015 at 4:20 PM myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ 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
please add orEqual operator
it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: please add orEqual operator
`a ||= b` looks like an in-place logical or, like `+=`. `a = a || b` would have very different semantics to that which you propose. In Python this would be written: ```python if a in [1, 2, 3, 5]: # stuff ``` In JS we have similar but slightly less semantic: ```js if ([1, 2, 3, 5].indexOf(a) -1) { // stuff } ``` On Sunday, August 9, 2015, myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: please add orEqual operator
why create an array when there can be an operator. I think if we do survey people will like this, ||=, it's more expressive. On Sun, Aug 9, 2015 at 9:41 PM, Isiah Meadows isiahmead...@gmail.com wrote: Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js [1, 2, 3].contains(value); ``` As for the operator proposed here, there's already an existing proposal for a safer version which doesn't coerce: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator. On Sun, Aug 9, 2015, 19:02 Michael A. Smith mich...@smith-li.com wrote: I was going to suggest a Set, now that ECMA has them… http://www.ecma-international.org/ecma-262/6.0/index.html#sec-set-objects ```js if ((new Set([1,2,3,5]).has(a)) { // stuff } ``` On Sun, Aug 9, 2015 at 4:20 PM myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ 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 ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: please add orEqual operator
Isn't prop ||= 0; better than prop = prop || 0; and it can be even defined like this. prop ||= var1 ||= var2 ||= 0; but then i dont know how we can use it ike this if (num == 3 ||=4 ||=6) On Sun, Aug 9, 2015 at 9:47 PM, myemailu...@gmail.com wrote: why create an array when there can be an operator. I think if we do survey people will like this, ||=, it's more expressive. On Sun, Aug 9, 2015 at 9:41 PM, Isiah Meadows isiahmead...@gmail.com wrote: Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js [1, 2, 3].contains(value); ``` As for the operator proposed here, there's already an existing proposal for a safer version which doesn't coerce: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator. On Sun, Aug 9, 2015, 19:02 Michael A. Smith mich...@smith-li.com wrote: I was going to suggest a Set, now that ECMA has them… http://www.ecma-international.org/ecma-262/6.0/index.html#sec-set-objects ```js if ((new Set([1,2,3,5]).has(a)) { // stuff } ``` On Sun, Aug 9, 2015 at 4:20 PM myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ 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 ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: please add orEqual operator
Or, there is the likely ES7 Array#contains for comparing multiple numbers. ```js [1, 2, 3].contains(value); ``` As for the operator proposed here, there's already an existing proposal for a safer version which doesn't coerce: http://wiki.ecmascript.org/doku.php?id=strawman:default_operator. On Sun, Aug 9, 2015, 19:02 Michael A. Smith mich...@smith-li.com wrote: I was going to suggest a Set, now that ECMA has them… http://www.ecma-international.org/ecma-262/6.0/index.html#sec-set-objects ```js if ((new Set([1,2,3,5]).has(a)) { // stuff } ``` On Sun, Aug 9, 2015 at 4:20 PM myemailu...@gmail.com wrote: it could be used like this: if ( a == 1 ||= 2 ||=3 ||=5) { //do something if a is either 1,2,3,5} and it could be used like this a || = 0 // a = a || 0 thanks ___ 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 ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss