What is the “get” keyword before a function in a class?
问题 What does get mean in this ES6 class? How do I reference this function? How should I use it? class Polygon { constructor(height, width) { this.height = height; this.width = width; } get area() { return this.calcArea() } calcArea() { return this.height * this.width; } } 回答1: It means the function is a getter for a property. To use it, just use it's name as you would any other property: 'use strict' class Polygon { constructor(height, width) { this.height = height; this.width = width; } get