What is the “get” keyword before a function in a class?

前端 未结 4 1023
执念已碎
执念已碎 2020-12-13 03:02

What does get mean in this ES6 class? How do I reference this function? How should I use it?

class Polygon {
  constructor(height, width) {
           


        
4条回答
  •  悲&欢浪女
    2020-12-13 03:42

    It is getter, same as Objects and Classes in OO JavaScript. From the MDN Docs for get:

    The get syntax binds an object property to a function that will be called when that property is looked up.

提交回复
热议问题