Skip to content

Commit

Permalink
Further improvements to console stubbing method
Browse files Browse the repository at this point in the history
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 750bf0e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/plugins.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
}
}
}());

Expand Down

0 comments on commit 750bf0e

Please sign in to comment.