# Code Style Guide for SparkPost Node SDK Please make sure that your editor is properly reading from the .editorconfig file located at the base of the repository. Please take a few minutes and review our style guide: The following provide a reasonable style and formatting guide for all Javascript produced at Message Systems. The most important take-away from this guide is: be consistent. A lot of effort has been made to keep this guide focused on style and formatting. However, conventions and techniques are inevitably part of things as well. These have been minimized as much as possible, as other documents are better suited to handle them. ## Naming Conventions Avoid single letter names outside of loops. Offer descriptive names. ``` // Bad function q() {...} // Good function query() {...} for (var i = 0; i < 10; i++) { ... } ``` Use camelCase when naming objects, functions, and instances. ``` // Bad var MYObject = {}; var my_string_variable = ''; var my-object-variable = {}; // Good var myObject = {}; var myStringVariable = ''; var myObjectVariable = {}; ``` Use PascalCase for class names. ``` // Bad var superHero = function (options) { this.name = options.name; }; var reed = new superHero({ name:'Reed Richards' }); // Good var SuperHero = function (options) { this.name = options.name; }; var reed = new SuperHero({ name:'Reed Richards' }); ``` Do not treat "private" object properties as special with something like an underscore. If you need private properties, obtain them by closing over them in the constructor. ``` // Bad this._ccNumber = '4111111111111111'; // Good function AccountInfo(cardNumber) { var cardNumber = cardNumber; // initialization, &c. return this; } var acct = new AccountInfo('4111111111111111'); ``` If you are making a reference to this, use self (assuming a bind() function isn't used). ``` // Bad function () { var that = this; return function () { console.log(that); }; } // Good function () { var self = this; return function () { console.log(self); }; } ``` You're not a minifier. Save yourself the headache of trying to be one. ``` // Bad var q = function q(s) { return document.querySelectorAll(s); }; var i,a=[],els=q('#test'); for(i=0;i