Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How "bad" is this constructor really?

While following a HTML5 rocks web audio tutorial JSHint gives this warning...

W056 - Bad constructor.at line 26 col 73

For the following line...

var audioContext = new (window.AudioContext || window.webkitAudioContext)();

The JSHint docs explain the warning is issued whenever new is used with an object literal and go on to say that new "is only useful for creating instances of a constructor function and has no sensible meaning when applied to non-function objects or literals."

This strikes me as a reasonable use though, it's succinct and it's pretty obvious what it's doing. I'm therefore minded to throw in an ignore directive /*jshint -W056 */ but I thought I'd ask in case I'm missing something.

So, am I missing something?

like image 978
Roger Heathcote Avatar asked May 25 '16 11:05

Roger Heathcote


1 Answers

The message you're getting doesn't match the code. New is used with a constructor function. JSHint probably can't tell this though because of the complex expression it's coming from. So it's wrong about there being no sensible meaning.

like image 110
fgb Avatar answered Oct 29 '22 00:10

fgb