Created
October 23, 2012 09:23
-
-
Save demonixis/3937838 to your computer and use it in GitHub Desktop.
Paramètres booléens par défaut en JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo (params) | |
{ | |
// Paramètres de la fonctions ils peuvent être vide | |
var params = params || {}; | |
// Prendra toujours true à cause de l'opération || | |
var add = params.add || true; | |
// Là la variable add prendre la bonne valeur | |
var add; | |
if (typeof(params.add) == "undefined") | |
add = true; | |
else | |
add = params.add; | |
var object = params.object || null; // Là c'est bon on récupère l'objet si il existe pas pas null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment