Mancy icon indicating copy to clipboard operation
Mancy copied to clipboard

Redclare const / class

Open MarkusPfundstein opened this issue 8 years ago • 2 comments

Hi Prince,

awesome REPL! Thanks for the job. I wonder if it is possible to implement a feature so that we can redclare const variables or classes. Right now this fails:

class F {
  constructor(A) {
    this.a = A;
  }
}

class F {
  constructor(a) {
    this.a = a*a;
  }
}
TypeError: Identifier 'F' has already been declared

as well as:

const g = x /0             // <- ERROR
ReferenceError: x is not defined     
const g = x => x /0   // <- oh, lets fix it
TypeError: Identifier 'g' has already been declared

Which is kinda annoying if you just want to play around with some data types. The fix in the later example is to just say g = x => x/0 without let/const, but that is a bit weird.. For the class example. I don't know a fix...

Would be go cool if this can be solved somehow or maybe theres a workaround?

Greetings Markus

MarkusPfundstein avatar Sep 24 '16 05:09 MarkusPfundstein

@MarkusPfundstein const and class are not really working well within REPL context. Worst case solution is to provide a way to clear the context or a way to traverse the context backwards.

princejwesley avatar Sep 24 '16 21:09 princejwesley

Or an icon in each execution output which will reset the context to that checkpoint.

princejwesley avatar Sep 24 '16 21:09 princejwesley