Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array pattern destructuring not actually supported? #6

Open
ninegrid opened this issue Jun 21, 2014 · 5 comments
Open

Array pattern destructuring not actually supported? #6

ninegrid opened this issue Jun 21, 2014 · 5 comments

Comments

@ninegrid
Copy link

When demonstrating generators:

function* fibonacci() {
  let a = 0, b = 1;

  while(true) {
    yield a;
    // this syntax doesnt appear to be actually supported
    [a, b] = [b, a + b];
  }
}

ReferenceError: Invalid left-hand side in assignment

I'm using node v0.11.13 with the --harmony flag.

@ninegrid
Copy link
Author

Sorry, I took another look at the document and saw at the bottom:

"We look forward for tasty syntax sugar yet to come, such as rest and spread operators, destructuring "...

@JustinDrake
Copy link
Owner

No no, this is good. Thanks for posting. :) All examples should run in the latest Node.

@JustinDrake JustinDrake reopened this Jun 22, 2014
@ninegrid
Copy link
Author

No problem then, I've been playing with harmony a lot lately and this resource is excellent. Though this feature is not currently present, it would appear that it is inbound in v8

@ronny-springer
Copy link

Hi Justin, there is a mistake in given Fibonacci example. If n is 0 it is 0 (e.g. Ron Knott's Fib table).

I share my code at jsbin.com for ES5

// iterative
function fibonacci (n) {
    var i = 0,
        temp = [i, i + 1];

    for (i = 2; i <= n; i += 1) {        
        temp[i] = temp[i - 1] + temp[i - 2];
    }  

    return (temp[n]);
}

// recursive one liner (very slow if n > 50 ! & bad to read)
function f (n) {
  return ((n >= 2) ? f (n - 1) + f (n - 2) : n);
}

@ninegrid
Copy link
Author

@ronny-springer perhaps you should create a seperate issue for that so that it gets noticed. This issue has to do with destructuring syntax in general and not the fibonacci example per se...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants