Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 750bf0e093a0a80ad785e38f23db38ad077a2d80 1 parent dc00673
Hans Christian Reinl drublic authored
Showing with 6 additions and 1 deletion.
  1. +6 −1 js/plugins.js
7 js/plugins.js
View
@@ -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;
+ }
}
}());
Please sign in to comment.
Something went wrong with that request. Please try again.