From 1222dec3a1246810acafee0c3e10aaffa243756a Mon Sep 17 00:00:00 2001 From: autologie <7351859+autologie@users.noreply.github.com> Date: Thu, 9 Nov 2023 00:25:36 +0100 Subject: [PATCH] perf: skip unnecessary access to cssText property --- lib/CSSStyleDeclaration.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js index 9e7b069..d74e739 100644 --- a/lib/CSSStyleDeclaration.js +++ b/lib/CSSStyleDeclaration.js @@ -18,11 +18,7 @@ var CSSStyleDeclaration = function CSSStyleDeclaration(onChangeCallback) { this._values = {}; this._importants = {}; this._length = 0; - this._onChange = - onChangeCallback || - function () { - return; - }; + this._onChange = onChangeCallback; }; CSSStyleDeclaration.prototype = { constructor: CSSStyleDeclaration, @@ -91,7 +87,9 @@ CSSStyleDeclaration.prototype = { } this._values[name] = value; this._importants[name] = priority; - this._onChange(this.cssText); + if (this._onChange) { + this._onChange(this.cssText); + } }, /** @@ -121,7 +119,9 @@ CSSStyleDeclaration.prototype = { // That's what Firefox does //this[index] = "" - this._onChange(this.cssText); + if (this._onChange) { + this._onChange(this.cssText); + } return prevValue; }, @@ -206,7 +206,9 @@ Object.defineProperties(CSSStyleDeclaration.prototype, { dummyRule.getPropertyPriority(name) ); } - this._onChange(this.cssText); + if (this._onChange) { + this._onChange(this.cssText); + } }, enumerable: true, configurable: true,