phiggins42 / has.js

Pure Feature Detection Library
936 stars 59 forks source link

Added console method detection #84

Closed cb1kenobi closed 2 years ago

cb1kenobi commented 13 years ago

I know has.js already has native-console detection, but doesn't detect individual methods (log, warn, error, etc), so I added a couple test cases. Probably only useful for gathering metrics.

Baggz commented 12 years ago

+1

jeffrose commented 12 years ago

I think adding console method detection is a good idea. That being said, there are a couple things wrong with the detection methods.

  1. Looping Performance - In general the for-in loop executes more slowly than the for loop. Since you're dealing with an array instead of an object, it would be more efficient to just use a for loop.
  2. Method Type - Checking whether the console method type is a function will not work because in IE the type is an object.

The console in IE is actually an injected C object, not a native JavaScript object. You can test that by checking for the existence of JavaScript function methods, e.g. typeof console.log.apply, which will return undefined in IE.