Permalink
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...
drublic committed Oct 14, 2012
1 parent dc00673 commit 750bf0e093a0a80ad785e38f23db38ad077a2d80
Showing with 6 additions and 1 deletion.
  1. +6 −1 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;
+ }
}
}());

0 comments on commit 750bf0e

Please sign in to comment.