steveosoule
11/20/2014 - 2:20 AM

Miva - Javascript Coding Standards

Miva - Javascript Coding Standards

// JavaScript Document

/* Use === OR !== to be more specific about comparisons */

/* Test for an element's existance */
function first_func() {
	if (!document.getElementById('id_name')) {
		return;
	};
 
	// If code gets here, element exists.
};

/* Spacings */
for (var i = 0, j = arr.length; i < j; i++) {
	// Do something.
};


/* If-else conditonals */
if (condition_1 === true) {
	// Do something.
}
else if (condition_2 !== 0) {
	// Do something.
}
else {
	// Do something.
};

/*
Closure
Self excecuting functions a will limit the scope of a variables use to within the function
*/
(function() {
	var first_variable = 'value 1';
	var second_variable = 'value 2';
 
	function first_func() {
		// Do something.
	};
 
	function second_func() {
		// Do something.
	};
})();

/* Objects */
var john_doe = {
	first_name: 'John',
	last_name: 'Doe',
	job: 'Everyman Respresentative',
	email: 'john.doe@example.com',
	married: true,
	age: 30
};

/* Arrays */
var doe_family = [
	'John',
	'James',
	'Jane',
	'Jenny',
	'Jared',
	'Jerome'
];