简体   繁体   中英

Why Mozilla documentation is mentioning that JS does not have class statement?

I was reading the introduction to JavaScript from Mozilla and noticed that at the Custom objects section it is mentioned that JS does not have classes ( at this line on GitHub ):

JavaScript is a prototype-based language that contains no class statement, as you'd find in C++ or Java (this is sometimes confusing for programmers accustomed to languages with a class statement). Instead, JavaScript uses functions as classes.

Why is the documentation saying so when I saw definitely the class statement being used like on the class section ?

Am I missing something or is the documentation obsolete?

I think what the Mozilla docs refer to is the fact that JS is not an object oriented programming language, but it is prototype based.

The keyword class in JavaScript is syntactic sugar (and a bit more) - under the hood a class is a special function built on prototypes:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

Thant said the docs you have referenced should probably be rephrased in light of ES6 changes to make it less confusing

Its True JavaScript is a functional programming language rather than an Object oriented Programming Language. The reason there are classes present is due to fact most of people find it easy to work with objects and classes like in other programming languages.

But in the end the code with classes get boiled down to functions and objects which the programmer need not know. So classes are merely a syntactic sugar which means a way to write code more programmer friendly.That is why you see class in some code. But in reality in the JS runtime classes are simply functions. so there is no class in JS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM