Not understanding this JavaScript warning...

I'm working on older code, written before JavaScript became all beautiful and did your laundry, and a bunch of lines of code are highlighted and probably false flags, but I'm not understanding some of the warnings they're giving as I'm not fully educated on all of the proper ways to rewrite our old code to fit proper JavaScript amazingness:

The function is just a simple function to convert the currency of a certain amount... it will never be called with 'new', I don't care nor did I know it had a constructor nor that it could, and I don't care whether it returns a primitive value or not, it's just supposed to return a number in the specified converted currency.

I know I can turn off each of these obnoxious highlight & pop-up warnings, but this is old code, and I don't think it should be open to inspection as if it's new amazing beautiful modern JavaScript.

Is there some way to specify that this code is ugly old decrepit vanilla JavaScript? I guess it's ES5, or ES3? I'm not sure... I just need PHPStorm to stop acting like it needs to be ES6 or ES9 or whatever the modern awesome do-everything JavaScript nowadays is.


The error is reported because your function name starts with upper case... Technically speaking, in legacy javascript any function is a constructor, i.e. can be called with new(). And starting constructor name with capital letter is a common practice that helps to distinguish constructor from regular function.

As you are (probably) not permitted to rename functions in your legacy code, I'd suggest disabling Probable bugs | Constructor returns primitive value inspection in Settings | Editor | Inspections | JavaScript,or suppressing it for return statement by adding

// noinspection JSConstructorReturnsPrimitive



Please sign in to leave a comment.