Consider the following JavaScript function:
function Foo() {
function getPreferences() {
if ([there is an existing preferences object]) {
return preferences;
}
return false;
}
}
The calling code is:
var foo = new Foo();
var prefs = foo.getPreferences();
if (prefs) {
// do something with prefs
}
- Is the pattern of returning an object if it exists, or false otherwise, seen as a good or bad practice? Other alternatives I can see are to return an empty object {} or null.
- Does this pattern have a name?