Confirmed users
14,525
edits
Line 123: | Line 123: | ||
<pre>controller.assertJSProperty(someObject.someProperty, expectedValue);</pre> | <pre>controller.assertJSProperty(someObject.someProperty, expectedValue);</pre> | ||
* Geo: Not necessarily needs definition in style guide; “Use the most appropriate function” can be a common sense standard. | * Geo: Not necessarily needs definition in style guide; “Use the most appropriate function” can be a common sense standard. | ||
; Element Before Action | |||
* Proposed Guideline: | |||
** Always declare an element before performing an action on it | |||
** Example: | |||
<pre> | |||
var obj = new elementGetter(params); | |||
controller.action(obj, params); | |||
</pre> | |||
* Geo: Element getting will be considerably simpler post-refactor and won’t require a long line. | |||
; Iteration | |||
* Proposed Guideline: | |||
** Use array.forEach() for iterating arrays | |||
** Use traditional for() for iterating strings | |||
<pre> | |||
array.forEach(function(elem, [index, [array]]) { | |||
statements; | |||
}, [thisObject]); | |||
</pre> | |||
* Geo: Documentation should call out that thisObject is the fourth parameter | |||
* Henrik: index and array are optional but can be helpful in some cases when you need the current index or other elements from the array. | |||
; General Formatting | |||
* Proposed Guideline: | |||
** Adhere to an 80 character per line limitation | |||
** In most cases, indentation should be 2-spaces from the parent | |||
* Geo: This keeps it mostly aligned with the actual structure. When we pull it back to the 0-column, makes things that are variables decls look like flow control structures instead, and I really don’t like that. | |||
Examples: | |||
* Function call: | |||
<pre> | |||
controller.function( | |||
param1, | |||
param2, | |||
paramN | |||
); | |||
</pre> | |||
* Variable from Function call: | |||
<pre> | |||
var obj = controller.method( | |||
param1, | |||
param2, | |||
paramN | |||
); | |||
</pre> | |||
* XPath: | |||
<pre> | |||
var obj = new elementslib.Lookup( | |||
controller.window.document, | |||
‘/path’ + | |||
‘/to’ + | |||
‘/object’ | |||
); | |||
</pre> | |||
* Arrays: | |||
<pre> | |||
var obj = [ | |||
{ child: ‘value’, | |||
child: ‘value } | |||
{ child: ‘value’, | |||
child: ‘value} | |||
]; | |||
</pre> |