Skip to content

Instantly share code, notes, and snippets.

View xcarpentier's full-sized avatar
🌐
Remote!

Xavier Carpentier xcarpentier

🌐
Remote!
View GitHub Profile
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(200);
@xcarpentier
xcarpentier / all_in_one.js
Last active August 29, 2015 14:06
AngularJS Style Guide 1 : La responsabilité unique
/* A éviter */
angular
.module('app', ['ngRoute'])
.controller('SomeController' , SomeController)
.factory('someFactory' , someFactory);
function SomeController() { }
function someFactory() { }
/* Recommandé */
// app.module.js
angular
.module('app', ['ngRoute']);
/**
* A éviter
*/
// logger.js
angular
.module('app')
.factory('logger', logger);
// La fonction logger est ajoutée comme une variable globale
/**
* À éviter
*/
var app = angular.module('app', [
'ngAnimate',
'ngRoute',
'app.shared',
'app.dashboard'
]);
/**
* À éviter
*/
var app = angular.module('app');
app.controller('SomeController' , SomeController);
function SomeController() { }
/**
* Recommandé
/**
* À éviter
*/
angular
.module('app')
.controller('Dashboard', function () { });
.factory('logger', function () { });
/**
* Recommandé
<!-- A éviter -->
<div ng-controller="Customer">
{{ name }}
</div>
<!-- Recommandé -->
<div ng-controller="Customer as customer">
{{ customer.name }}
</div>
/* A éviter */
function Customer ($scope) {
$scope.name = {};
$scope.sendMessage = function () { };
}
/* Recommandé, mais il y a encore mieux, à suivre ... */
function Customer () {
this.name = {};
this.sendMessage = function () { };
/* A éviter */
function Customer () {
this.name = {};
this.sendMessage = function () { };
}
/* Recommandé */
function Customer () {