From 9ef3f8d2ed6a2ba6e3b5eab8e50983a1abb1c957 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Fri, 13 Nov 2009 12:27:10 -0500 Subject: [PATCH] Eliminate runtime forking and long method lookup in `Element.hasAttribute`. --- CHANGELOG | 2 ++ src/dom/dom.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f762443..a194049 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Eliminate runtime forking and long method lookup in `Element.hasAttribute`. (kangax) + * Remove redundant ternary. (kangax) * Avoid repeating declaration statements where it makes sense, for slightly better runtime performance and minification. (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index a3db44c..7876327 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -2036,10 +2036,14 @@ Element.extend = (function() { return extend; })(); -Element.hasAttribute = function(element, attribute) { - if (element.hasAttribute) return element.hasAttribute(attribute); - return Element.Methods.Simulated.hasAttribute(element, attribute); -}; +if (document.documentElement.hasAttribute) { + Element.hasAttribute = function(element, attribute) { + return element.hasAttribute(attribute); + }; +} +else { + Element.hasAttribute = Element.Methods.Simulated.hasAttribute; +} /** * Element.addMethods(methods) -> undefined