These are merely guidelines. They should not be adhered to mechanically, especially if a deviation would make your code more readable.
Construct | Convention | Examples |
---|---|---|
Pseudoclass name (i.e., constructor function) | CamelCase with an initial capital letter | MightyBalrog, MagicWeapon
|
Namespace name | camelCase with an initial lowercase letter | clericSpells, savingThrows
|
Public method | camelCase with an initial lowercase letter | castDimensionalDoorway, rollForInitiative
|
Public variable | camelCase with an initial lowercase letter | materialComponents, hasTrackingAbilities |
Private method | camelCase with an initial lowercase letter and underscore | _getHealth |
Private variable | camelCase with an initial lowercase letter and underscore | _backstabAbility |
Method arguments | camelCase with an initial lowercase letter | halfOrcArmy |
Local variables | camelCase with an initial lowercase letter | isHumanoid, levelCount |
'Constants' | Uppercase with underscores | CLERIC_PLAYER, GAME_MASTER |
Ennumeration keys | Uppercase with underscores | characterClass.MAGIC_USER, armorTypes.PLATE_MAIL |
wizard_hat, vorpal_blade
wizardHat, vorpalBlade
bartenderNPC, newRPG
bartenderNpc, newRpg
dekaiKatana
giganticSword
wndMnstr[3]
wanderingMonster[3]
var magicItemCount;
var wizardNpc;
var magicItemCount = 0;
var wizardNpc = null;
var currentThiefLevel = 8;
var canBackstab = true;
var isNpc = true;
var currentThiefLevel = 8;
var canBackstab = true;
var isNpc = true;
tempString, tmpDate
str, dt
42
ANSWER_TO_THE_QUESTION_OF_LIFE
function checkForTraps(dexterity, level) {
// Do stuff to check for traps here
}
var checkForSecretDoors = function (race, level) {
// Stuff for check here
};
if (gotInitiative) {
attackDragon();
}
else if (speaksDragon) {
tryNegotiating();
}
else {
runAway();
}
for (var i = 0; i < guards.length; i++) {
rollTwentySided(guards[i]);
}
while (charactersInjured) {
castCureLightWounds();
charactersInjured = checkCharacterHealth();
}
switch (characterClass) {
case 'ranger':
// Ranger special stuff here
// Fallthrough
case 'fighter':
// Do fighter stuff
break;
case 'magicUser':
// Do mage-specific stuff
break;
default:
// do nothing
}
try {
pickPocket();
}
catch (e) {
lookInconspicuous();
reportBack(e);
}
finally {
runLikeHell();
}
var obj = {
spellName: 'Invisible Stalker',
numberOfFighters: 3,
checkForTraps = function() {
// Do trap checking
}
};
var obj = { staff: 'Staff of the Magi', wand:
'Wand of Negation', misc: 'Boots of Elvenkind' };
var rollInitiative = function() { // Roll die here };
var rollInitiative = function () { // Roll die here };
var localMonsterRumors = getLocalGossip(inkeeper,
localInn,
numberOfClerics,
pintsOfAlePurchased,
charismaAjustment);
var localMonsterRumors = getLocalGossip(inkeeper,
localInn, numberOfClerics, pintsOfAlePurchased,
charismaAjustment);
if (isUndead) grabFire();
if (isUndead) { grabFire(); }
if(isNpc) {
ignoreTalk();
}
if (isNpc) {
ignoreTalk();
}
function getArmorClass (armorType, dexterity) {
// Get AC stuff here
}
function getArmorClass(armorType, dexterity) {
// Get AC stuff here
}
getExperiencePoints(monster,hitPoints);
getExperiencePoints(monster, hitPoints);
var newCharacter = {
race:'gnome',
class:'figheter'
isNpc:false;
};
var newCharacter = {
race : 'gnome',
class : 'figheter'
isNpc : false;
};
var newCharacter = {
race: 'gnome',
class: 'figheter'
isNpc: false;
};
var message = speaksDrow? getMessageinDrow():'You do not speak Drow.';
var message = speaksDrow ? getMessageinDrow() : 'You do not speak Drow.';
var thaco = hit+adjustment-randomFactor;
var thaco = hit + adjustment - randomFactor;
var elem = document.getElementById('charClass-' + charClass +
+ '_combatStats-' + armorClass + '-' + toHitBonus);
var char = 'charClass-' + charClass;
var combat = 'combatStatus-' + armorClass + '-' + toHitBonus;
var elem = document.getElementById(char + '_' + combat);