Talk:JavaScript Preferences Class

From MozillaZine Knowledge Base
Jump to navigationJump to search

Regarding default values for prefs

There's a concept of Default preferences in Mozilla prefs system. I really like it and prefer using it over using methods like get*PrefDef(aPrefName, aDefaultValue) (that is, wrapping calls to prefs XPCOM in try { } catch blocks or checking value type), because:

  1. All default values are in one place, where they can easily be reviewed and changed.
    • In particular, if you read a pref in two different parts of code, you don't have to duplicate default values, as you would have to, if you were using get*PrefDef.
  2. The prefs read from 'defaults' files are displayed in about:config, helping power users to find "hidden" prefs.
  3. Support for locked prefs - for free.

When using 'defaults', wrong type of a preference or anything else that makes get*Pref method of nsIPrefBranch fail, is an exception and should be handled as such instead of just silently putting a hard-coded default value there.

asqueella

Hi Asqueella, How does an extension install default preferences? I was trying to solve the problem which arises when default preferences do not exist.

grimholtz