From 750bf0e093a0a80ad785e38f23db38ad077a2d80 Mon Sep 17 00:00:00 2001 From: Hans Christian Reinl Date: Sun, 14 Oct 2012 15:15:07 +0200 Subject: [PATCH] Further improvements to `console` stubbing method These improvements are: - cache current method in `while`-loop to reduce property look-ups - use `if` as the conditional assignment in `while`-loop in order to improve performance and readability Reference: commit 578f377 Closes gh-1229 --- js/plugins.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/plugins.js b/js/plugins.js index 3cfc65235c..90ec0bedcb 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -1,5 +1,6 @@ // Avoid `console` errors in browsers that lack a console. (function() { + var method; var noop = function noop() {}; var methods = [ 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', @@ -11,8 +12,12 @@ var console = (window.console = window.console || {}); while (length--) { + method = methods[length]; + // Only stub undefined methods. - console[methods[length]] = console[methods[length]] || noop; + if (!console[method]) { + console[method] = noop; + } } }());