Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread 段垚
Because `foo.bar` is equivlant to `foo['bar']` in JS so far, and `array.-1` could break this consistency. On the other hand, `array.first()` seems not necessary because `array[0]` is even more handy; `array.last()` looks fine to me. If someone prefer a more general solution, I recommand

Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Jeff Walden
On 09/27/2016 05:38 AM, Bob Myers wrote: > To my knowledge no-one has ever explained why the following is a bad idea: > > ``` > array.0 > array.-1 > ``` Consider this already-valid code: var first = array .0.toString(); This parses *right now* as var first = array; (0.0).toString();

Re: Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Caitlin Potter
> On Sep 27, 2016, at 6:24 PM, Li Xiaolong <898310...@outlook.com> wrote: > > > That’s not necessarily true — `await` in modules may be very different from > > this. > > I don’t know what await in modules look like. It’s still being discussed. I think there are some strong arguments for

Re: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Li Xiaolong
Reply to Bob Myers: > I don't think it's that obvious. I'm not a parsing guy, but I don't think the parser works backward, looking for dots preceding numbers. I would assume simplistically that a dot following an expression currently puts the parser into a mode where it is looking for the

答复: Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Li Xiaolong
> That’s not necessarily true — `await` in modules may be very different from > this. I don’t know what await in modules look like. > You might be confused about something — if an awaited Promise is rejected, > the async function can be resumed from a catch block to handle the rejection.

Re: Re: Syntax Proposal: Add getter/setter directly on current scope ??

2016-09-27 Thread Nicu Micleusanu
It does not make sense for me because you already have access to all the values available in the current context, there is no need to make things more complex and to add a getter. ___ es-discuss mailing list es-discuss@mozilla.org

Re: Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Caitlin Potter
> On Sep 27, 2016, at 5:23 PM, Li Xiaolong <898310...@outlook.com> wrote: > > Sorry I’m not familiar with es7. But I still thing my OMP is better than > async/await. > 1: the await keyword can only be used in an async function, so each time you > want to await you have to add async before

Re: Re: Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Li Xiaolong
Sorry I'm not familiar with es7. But I still thing my OMP is better than async/await. 1: the await keyword can only be used in an async function, so each time you want to await you have to add async before outer function. 2: async/await still use promise to handle async, which is not as clear as

Re: Syntax Proposal: Add getter/setter directly on current scope ??

2016-09-27 Thread Bergi
Li Xiaolong schrieb: Sometimes, we want to get a representation of another variable, or get an abstract representation of some other variables. In this case, we often use getter/setter. But defining a getter/setter in current scope is complex. Can we make adding a getter or setter to current

Re: Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Bergi
What you call "one more point" already exists as the `await` keyword and is much more powerful than a limited `.return` operator: Please make sure to be familiar with the topic before making further proposals. - Bergi

Re: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Andrea Giammarchi
I don't think I've ever seen an `arr[-1]` access that wasn't meant to grab last value same as `arr.slice(-1)` would do. If you deal with arrays and you are treating them as generic objects and you store numeric values like `-1` I'm not sure why would you do that or what's your use case, all I

Re: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Li Xiaolong
Reply to Bob Myers: Maybe you are right. It's just most programmers are not used to variables or properties that starts with a number. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Proposal: use "One More Point" to handle async functions

2016-09-27 Thread Li Xiaolong
The traditional callback method to handle async is not elegant and clear. Even the promised style is kind of odd. So I got an idea that we use "One More Point"(OMP) to make async coding easier to use. For example: ```js //Without One More Point: function async(args, callback) { ...

Re: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Bob Myers
> If you use `a.-1` to represent `a[length-1]`, so how do we refer to the value of the `-1` property? `a[-1]`, as at present. > It is obvious that ‘.’ before a number will be recognized as a decimal point, I don't think it's that obvious. I'm not a parsing guy, but I don't think the parser

Syntax Proposal: Add getter/setter directly on current scope ??

2016-09-27 Thread Li Xiaolong
Sometimes, we want to get a representation of another variable, or get an abstract representation of some other variables. In this case, we often use getter/setter. But defining a getter/setter in current scope is complex. Can we make adding a getter or setter to current scope easier like the

转发: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Li Xiaolong
It is obvious that ‘.’ before a number will be recognized as a decimal point, which is different from the point that gets a property. For example, .2===0.2 is true. What’s more, the array’s prototype is object, which means arr[-1] will get the value of -1 rather than length-1. The array can store

Re: Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Nicu Micleusanu
Well, `String.prototype.match()` does this, it returns an array of matches or `null` in case there are no matches. I agree that in some situation this can be a source of errors, but the implementation would be quite useful. In case it's not acceptable, I would propose read-only members

Re: Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Bob Myers
This is well-traveled territory. Whatever is or is not implemented, interfaces which have optional arguments and return scalars in one case and arrays in another case are a horrible idea. To my knowledge no-one has ever explained why the following is a bad idea: ``` array.0 array.-1 ``` Bob

Proposal: Array.prototype.first() and Array.prototype.last()

2016-09-27 Thread Nicu Micleusanu
I propose to standardize `Array.prototype.first()` and `Array.prototype.last()`, very similar to underscore `_.first()` and `_.last()`. A very basic implementation: ```js Array.prototype.first = function (n) { if (!arguments.length) { return this[0]; } else {