Re: for statement with index and value

2015-07-13 Thread Jorge Bucaran
Unless you have a specific requirement I am missing, your use case is more elegantly resolved IMO using a custom generator that yields exactly the information you need per iteration. A functional approach using a function that has the information you need is also another valid solution. --

Re: Re: for statement with index and value

2015-07-13 Thread aakarsh1997
Do we have anything similar for iterating objects with property names as well? (as asked in the original post as well) Thanks! ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: for statement with index and value

2015-07-13 Thread Tingan Ho
Yes the proposed syntax is a special case for arrays. tis 14 juli 2015 kl 12:23 skrev Edwin Reynoso : > Something wrong with server that doesn't let me edit. > > But what I meant by the first code snippet was: > > ```JS > for(let a, b of new Set([1,2])) // what would `a` and `b` be here? How > wo

Re: for statement with index and value

2015-07-13 Thread Edwin Reynoso
Something wrong with server that doesn't let me edit. But what I meant by the first code snippet was: ```JS for(let a, b of new Set([1,2])) // what would `a` and `b` be here? How would it know what to extract?? ``` Would `b` just be `undefined`, yet for an array it returns the `index` how does it

Re: for statement with index and value

2015-07-13 Thread Edwin Reynoso
So I'm assuming this would be special to arrays?? because destructuring works fine for anything that's iterable: meaning how would it know what to take out for Sets?? ```JS for(let value, index of [1,2]) { // do something } ``` With destructuring we at least know what's being extracted (not su

Re: for statement with index and value

2015-07-13 Thread Tingan Ho
>Unfortunately we can't have both... ``` for (let [index, value] of values){ ``` I was suggesting the syntax: ``` for (let value, index of values){ ``` `value` comes first and no `[ ... ]`. On Tue, Jul 14, 2015 at 11:52 AM, Logan Smyth wrote: > Unfortunately we can't have both > > ``` > for (

Re: for statement with index and value

2015-07-13 Thread Logan Smyth
Unfortunately we can't have both ``` for (let value of values){ ``` and ``` for (let [index, value] of values){ ``` Over all, the first one is the more likely one on a day-to-day basis. The `[]` are needed because the `for...of` follows the standard rules for assignment, so it uses standard de

Re: for statement with index and value

2015-07-13 Thread Tingan Ho
>for (let [index, value] of [1, 2, 3].entries()) console.log(index + ": " + value) I still think most people will write: ``` for (let value of values) { ... } ``` and then rewrite the whole expression inside the `for-loop` when they find out that they need the index too: ``` for (let [ind

Re: for statement with index and value

2015-07-13 Thread Kevin Smith
Destructuring is here to help: for (let [index, value] of [1, 2, 3].entries()) console.log(index + ": " + value) The "entries" method returns an iterator of [index, value] pairs. On Mon, Jul 13, 2015 at 10:13 PM Tingan Ho wrote: > Just following a discussion we had on TypeScript >

for statement with index and value

2015-07-13 Thread Tingan Ho
Just following a discussion we had on TypeScript https://github.com/Microsoft/TypeScript/issues/3835 In most times, I just need the value in an array, so I use a for..of loop. But then, I find out that I need the index too, then I need to rewrite my whole for loop expression. Happens all the time

Re: Generalize do-expressions to statements in general?

2015-07-13 Thread Mark Miller
On Mon, Jul 13, 2015 at 6:53 PM, Isiah Meadows wrote: > To be perfectly honest, though, I'm not entirely sure the specifics of the > do-expression proposal, since Google is failing me here (can't find a thing > giving more detail than this mailing list). And as for what my proposal > here is, I f

Re: Generalize do-expressions to statements in general?

2015-07-13 Thread Isiah Meadows
On Mon, Jul 13, 2015 at 7:53 PM, Isiah Meadows wrote: > > To be perfectly honest, though, I'm not entirely sure the specifics of the > do-expression proposal, since Google is failing me here (can't find a thing > giving more detail than this mailing list). And as for what my proposal here > is,

Re: Generalize do-expressions to statements in general?

2015-07-13 Thread Isiah Meadows
To be perfectly honest, though, I'm not entirely sure the specifics of the do-expression proposal, since Google is failing me here (can't find a thing giving more detail than this mailing list). And as for what my proposal here is, I forgot to mention that expression statements would be explicitly

Re: Generalize do-expressions to statements in general?

2015-07-13 Thread Mark S. Miller
Interesting. Got me thinking. Here's an alternate proposal I'll call "do expressions without the 'do'." At < https://people.mozilla.org/~jorendorff/es6-draft.html#sec-expression-statement> we have the syntax of the expression statement. Ignoring sloppy "let" nonsense, this says that an expression

Generalize do-expressions to statements in general?

2015-07-13 Thread Isiah Meadows
I was reading a recent thread where do-expressions simplified a common try-catch use case, and I was wondering if `do` could be simplified to an expression? It would allow for this to be solved very easily, but also add a lot mo

Re: Instance bound class methods

2015-07-13 Thread Andrea Giammarchi
FWIW I've just added an extra possible solution to what is a very common problem: https://github.com/zenparsing/es-function-bind/issues/17#issuecomment-120978833 it uses mixins, but I would personally vote +1 to have `::obj.method` returning every time the same method. Best Regards On Mon, Jul 1

Re: Instance bound class methods

2015-07-13 Thread Matthew Robb
What I'd really like to have in the language is the ability to store a property access into a single binding: ``` let someObj = { doStuff(){} }; let doStuff = #someObj.doStuff; doStuff(); ``` Treated as: ``` let someObj = { doStuff(){} }; someObj.doStuff(); ``` - works with any property access

RE: Instance bound class methods

2015-07-13 Thread Domenic Denicola
From: es-discuss [mailto:es-discuss-boun...@mozilla.org] On Behalf Of Brendan Eich > You're counting on the property assignment being moved into the constructor, > where `this` is bound. In a class body in ES6 (without property assignment > extension), especially in the top level where method d

Re: Instance bound class methods

2015-07-13 Thread Kevin Smith
> I am curious if https://github.com/zenparsing/es-function-bind would be > related, since it would allow bound function calls to be made by using > `obj::fn` while `obj.fn` would result in the unbound first class function. > Well, for that syntax proposal, it would be `::obj.fn`. But see https:/

Re: Instance bound class methods

2015-07-13 Thread Bradley Meck
I am curious if https://github.com/zenparsing/es-function-bind would be related, since it would allow bound function calls to be made by using `obj::fn` while `obj.fn` would result in the unbound first class function. On Mon, Jul 13, 2015 at 10:02 AM, Brendan Eich wrote: > You're counting on the

Re: Instance bound class methods

2015-07-13 Thread Brendan Eich
You're counting on the property assignment being moved into the constructor, where `this` is bound. In a class body in ES6 (without property assignment extension), especially in the top level where method defintiions go, `this` isn't obviously bound to the newly constructed instance. Ok, that

Re: Instance bound class methods

2015-07-13 Thread Bucaran
This and arrow generators would be a nice thing to have. > On Jul 13, 2015, at 11:42 PM, Matthew Robb wrote: > > Are there any proposals or any discussions around solving the problem of > instance bound class methods with some sugar? > > There are examples of people doing things like this: >

Instance bound class methods

2015-07-13 Thread Matthew Robb
Are there any proposals or any discussions around solving the problem of instance bound class methods with some sugar? There are examples of people doing things like this: https://github.com/reactjs/react-future/blob/master/01%20-%20Core/01%20-%20Classes.js#L31 My proposal would be to extend meth

Re: Re: insteadof operator

2015-07-13 Thread Nick Krempel
On 11 July 2015 at 14:40, monolithed wrote: > ```c++ > #include > > static int foo = 1; > > int bar (const int &foo) { > ::foo = 2; > > return foo; > } > > int main () { > std::cout << foo << ',' << bar(1) << std::endl; // 2,1 > (This looks like undefined behavior as the evaluation of "foo" and

Re: Allow `try…catch` blocks to return a value.

2015-07-13 Thread Bucaran
Exactly, but the reason I proposed this is because the method your are describing was not satisfactory enough / I found it inconvenient. Regards > On Jul 13, 2015, at 6:00 PM, Michał Wadas wrote: > > let stuff = ()=>{ try { > return f(); > } catch(e){ return f; } }(); > 14 chars more. > >

Re: Counterintuitive native array methods behavior (.length > 2^32)

2015-07-13 Thread Ivan Vyshnevskyi
I believe, it's fixed in ECMAScript 2015: now check for `length` being < 2^32 is performed only on array creation [1], and < 2^53 when length is going to be updated [2]. See, for example, current algorithm of Array.prototype.forEach: http://www.ecma-international.org/ecma-262/6.0/#sec-array.protot

Re: Named Paramters

2015-07-13 Thread Benjamin Gruenbaum
If we _wanted_ to add named parameters, we would _probably_ have a _different_ name for the named parameter inside the function and outside the function. ```js function foo(x as y){ } foo(y = 5); ``` Or something like that. That said, I'm not convinced we _need_ named parameters, that they just

Re: Named Paramters

2015-07-13 Thread Michał Wadas
In fact, it's impossible. > And when the arguments are renamed during the minification, all > the labels in function calls can be minified accordingly too. You can't statically determine which function will be called. Minifier CAN'T know in general case if your $(selector='wow') calls jQuery or so

Counterintuitive native array methods behavior (.length > 2^32)

2015-07-13 Thread Michał Wadas
Steps to reproduce: let p = { 0: 'a', 1: 'b', 2: 'c', length: Math.pow(2,32)+1 }; Array.prototype.forEach.call(p, (el)=>console.log(el)); // logs only 'a' The cause of this behaviour is obvious for anyone that reads specification - every native Array.prototype methods perform abstract operation `

Re: Allow `try…catch` blocks to return a value.

2015-07-13 Thread Michał Wadas
let stuff = ()=>{ try { return f(); } catch(e){ return f; } }(); 14 chars more. 2015-07-13 10:14 GMT+02:00 Andreas Rossberg : > Do-expressions will solve this: > > let stuff = do { try { >f() > } catch (e) { 0 } } > > The inflation of braces is somewhat ugly there, and we might want to a

Re: Allow `try…catch` blocks to return a value.

2015-07-13 Thread Andreas Rossberg
Do-expressions will solve this: let stuff = do { try { f() } catch (e) { 0 } } The inflation of braces is somewhat ugly there, and we might want to allow dropping some of them. /Andreas On 12 July 2015 at 10:26, Gary Guo wrote: > This is not possible as it contracts with existing semant

Re: Named Paramters

2015-07-13 Thread Alexander Kit
This is extremely for the optional parameters important function foo (bar, bak=1, qux=2) { } // here I want `bar` to be default, but the `quux` take another value foo(5, qux: 3); People often suggest object destruction here, but it is then just a workaround. And when the arguments are renamed d