Skip to content

Instantly share code, notes, and snippets.

@jccrosby
Created July 24, 2012 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jccrosby/3170149 to your computer and use it in GitHub Desktop.
Save jccrosby/3170149 to your computer and use it in GitHub Desktop.
RealEyes Coding Standards
function Animal( name, health ) {
this.name = name;
this.health = health;
}
Animal.prototype.eat = function( value ) {
this.health += value;
};
function Snake( name, health ) {
Animal.call( this, name, health );
this.aggression = 50;
}
Snake.prototype = new Animal();
Snake.prototype.constructor = Snake;
Snake.prototype.eat = function( value ) {
Animal.prototype.eat.call( this, value );
this.aggression -= value;
};
var ralph = new Animal( 'Ralph', 50 );
ralph.eat( 50 );
var sid = new Snake( 'Sid', 100 );
sid.eat( 20 );
function distanceTo( startX, startY, endX, endY ) {
var dx = startX - endX;
var dy = startY - endY;
return Math.sqrt( dx * dx + dy * dy );
}
var moduleExample = ( function() {
var privateVariable = 'Module';
return {
publicProperty: 'moduleExample.publicProperty',
publicMethod: function() {
return privateVariable;
};
};
}() );
var someVar = 0;
if( typeof someVar === 'undefined' ) {
someVar = 0;
} else {
for( var i = 0; i < 10; i += 2 ) {
someVar += i;
}
}
switch( someVar ) {
case 0:
console.log( 'started as undefined' );
break;
case 20:
console.log( 'started as 0' );
break;
default:
console.log( 'neither' );
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment