why is class a reserved word in JavaScript?

后端 未结 5 1911
渐次进展
渐次进展 2020-11-29 08:25

I am planning to implement class inherit interface using JavaScript. class is the perfect word as the name of the constructor.

class = function          


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 08:59

    It's reserved to future-proof ECMAScript

    The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions.

    Don't fret though, if you're using best-practices in your JavaScripts, you're placing all accessible functions/variables/constructors in a namespace, which will allow you to use whatever name you'd like:

    foo = {};
    foo['class'] = function(){...code...};
    var myClass = new foo['class']();
    

提交回复
热议问题