From 9670b266968e47226d70e96e038d5e0aad4cfd4e Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Sat, 9 Dec 2017 17:46:32 +0800 Subject: [PATCH] Refactor Font.js --- src/Font.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Font.js b/src/Font.js index cd32f25..4c78bd2 100644 --- a/src/Font.js +++ b/src/Font.js @@ -63,9 +63,11 @@ export class FontMetrics { return {baseline, middle}; } getMetrics(font: Font) { - if (this._data[`${font.fontFamily} ${font.fontSize}`] === undefined) { - this._data[`${font.fontFamily} ${font.fontSize}`] = this._parseMetrics(font); + const key = `${font.fontFamily} ${font.fontSize}`; + if (this._data[key] === undefined) { + this._data[key] = this._parseMetrics(font); } - return this._data[`${font.fontFamily} ${font.fontSize}`]; + + return this._data[key]; } }