Closed Bug 899062 Opened 12 years ago Closed 12 years ago

Constructors for core SDK objects should follow Javascript capitalization conventions

Categories

(Add-on SDK Graveyard :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: coreyf, Unassigned)

Details

A common convention in Javascript is to reserve camel case styled functions as constructor functions (functions that require 'new'). Here are a few sources: JSLint: http://jslinterrors.com/a-constructor-name-a-should-start-with-an-uppercase-letter/ Eloquent Javascript: http://eloquentjavascript.net/chapter8.html#p212d0541 I think it's particularly confusing that the core objects in the SDK (like Request or Widget) are capitalized as though they are constructor functions, but don't require 'new'. Changing this would of course break existing code, but I think it's something to look into. One possible solution would be to do something like Leaflet does. http://leafletjs.com/reference.html#marker-l.marker They allow two different ways of constructing a Javascript object. In the case of Request in the SDK, they would be 'new Request()' or 'request()'. The relevant bug for Leaflet can be found here: https://github.com/Leaflet/Leaflet/pull/1430
These methods that start with a capital letter are constructors, the ones that don't are not. We do follow the practices in the links you provided. The 'new' is overly verbose and opt-in anyhow, so I don't see a need to change to make this required. Can we WONTFIX this Irakli?
Flags: needinfo?(rFobic)
Hi Corey, `Request` is created using `Class` from `heritage` module. From the docs: "Constructors created using Class function don't require new keyword (even though it can be used) for instantiation." (see: https://addons.mozilla.org/en-US/developers/docs/sdk/Firefox-22/modules/sdk/core/heritage.html) So I think it's already made in the way are you mentioned. If it doesn't work like that, then we have a bug.
Status: NEW → RESOLVED
Closed: 12 years ago
Flags: needinfo?(rFobic)
Resolution: --- → WORKSFORME
"The 'new' is overly verbose". Hah.
You need to log in before you can comment on or make changes to this bug.