2016-12-08 2 views
4

In Chrome Konsole:"Kennung [...] wurde bereits deklariert (...)". Wie kann die Klassenvariable in der Chrome Devtools-Konsole deaktiviert werden?

# One 
class A { 
    constructor(x) { this.x = x } 
} 

class A { 
    constructor(x, y) { this.x = x; this.y = y } 
} 

VM602:1 Uncaught SyntaxError: Identifier 'A' has already been declared(…) 


# Two 
class A { 
    constructor(x) { this.x = x } 
} 
delete A 
true 
class A { 
    constructor(x) { this.x = x } 
} 
VM805:1 Uncaught SyntaxError: Identifier 'A' has already been declared(…) 


# Three 
A = null 
null 
class A { 
    constructor(x) { this.x = x } 
} 
VM817:1 Uncaught SyntaxError: Identifier 'A' has already been declared(…) 

Und einfach keine Chancen auf eine Variable ohne Neuladen der Seite unscharf zu schalten. Gibt es irgendwelche Mittel zum Löschen/Löschen/Löschen/Löschen ohne Neuladen der Seite?

+0

dies tun Es passiert auch in Nodejs. Ab heute kann laut https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class die Klasse nicht zweimal deklariert werden. –

Antwort

2

Ich suche auch nach dieser Angelegenheit. Kann aber im Internet nichts Nützliches finden.

So verwendet nächste Workarround: Variable mit dem gleichen Namen wie Klasse deklarieren. Wie folgt aus:

var A = class A { constructor(x) { this.x = x } } 

new A(2) 
> A {x: 2} 

Das ist so, wie es neu definiert einfach:

var A = class A { constructor(x, y) { this.x = x; this.y = y } } 
new A(2,3) 
> A {x: 2, y: 3} 

Auch verwenden wir eine weitere Variable, noch wir Objekte mit Typ bekommen 'A'

var AZ = class A { constructor(x, y) { this.x = x; this.y = y } } 
new AZ(2,3) 
> A {x: 2, y: 3} 

Aber Klassendefinition gebrauchte Klassenname wird nicht erstellt:

var C = class B { constructor(x, y) { this.x = x; this.y = y } } 
new C(2,3) 
> B {x: 2, y: 3} 
new B(2,3) 
> VM342:1 Uncaught ReferenceError: B is not defined 
Verwandte Themen