Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we delete ES6 class?

Can we really delete a class create by es6 "class"?

class myClass{}
delete myClass;
console.log(myClass); //output: class myClass{}
var myClass=0; //Uncaught SyntaxError: Identifier 'myClass' has already been declared
like image 814
3142 maple Avatar asked Feb 11 '17 11:02

3142 maple


Video Answer


2 Answers

Delete will only delete object properties or a variable that is global.

like image 173
dale Avatar answered Oct 27 '22 04:10

dale


https://stackoverflow.com/a/44694753/461412

this answer is useful. yet not perfect.

i guess you could never delete it after it's declared as an identifier, but you could wrap it into a deletable variable in the first place.

still i'm looking for a better solution. our team is trying to build a detachable modules system. deadly, any declared class is not detachable. we don't like the idea of transpiling every module we load.

even Array is a property of Global. classes are not.

like image 21
AiShiguang Avatar answered Oct 27 '22 03:10

AiShiguang