virtual-labs-archive / physical-chemistry-iiith

Other
1 stars 64 forks source link

A function with a name starting with an uppercase letter should only be used as a constructor. (new-cap) #49

Open BSravanthi opened 5 years ago

BSravanthi commented 5 years ago

The new operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors. This rule is aimed at helping to distinguish regular functions from constructor functions. As such, it warns whenever it sees new followed by an identifier that isn't capitalized or whenever it sees capitalized function called directly without new operator. The following patterns are considered problems:

//Bad:
var friend = new person();
var colleague = Person();

//Good:
var friend = new Person();
var colleague = person();

Please refer to the following link to fix similar issues. https://app.codacy.com/app/BSravanthi/physical-chemistry-iiith/issues?&filters=W3siaWQiOiJMYW5ndWFnZSIsInZhbHVlcyI6W251bGxdfSx7ImlkIjoiQ2F0ZWdvcnkiLCJ2YWx1ZXMiOlsiQ29kZSBTdHlsZSJdfSx7ImlkIjoiTGV2ZWwiLCJ2YWx1ZXMiOltudWxsXX0seyJpZCI6IlBhdHRlcm4iLCJ2YWx1ZXMiOlsxNjE1XX0seyJpZCI6IkF1dGhvciIsInZhbHVlcyI6W251bGxdfSx7InZhbHVlcyI6W119XQ==

somashekhar31 commented 5 years ago

commit id:https://github.com/virtual-labs/physical-chemistry-iiith/pull/51/commits/5c2643b9e4395ee8a5d739f72bc0749d244afc01

snehitharangu commented 5 years ago

Valid fix @somashekhar31

samhithavootkoor commented 5 years ago

validated-2 @somashekhar31