Я знаю, что ElementMetrics
- это функция конструктора, а объект-прототип имеет ключ и значение. Но что означает get
в прототипе?Что значит «получить» в прототипе?
function ElementMetrics(element) {
this.element = element;
this.width = this.boundingRect.width;
this.height = this.boundingRect.height;
this.size = Math.max(this.width, this.height);
}
ElementMetrics.prototype = {
get boundingRect() {
return this.element.getBoundingClientRect();
},
furthestCornerDistanceFrom: function(x, y) {
var topLeft = Utility.distance(x, y, 0, 0);
var topRight = Utility.distance(x, y, this.width, 0);
var bottomLeft = Utility.distance(x, y, 0, this.height);
var bottomRight = Utility.distance(x, y, this.width, this.height);
return Math.max(topLeft, topRight, bottomLeft, bottomRight);
}
};
Это геттер (Свойство сбруя): https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/get – nils