Skip to content

Instantly share code, notes, and snippets.

@thibault
Last active April 21, 2017 09:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thibault/8801077 to your computer and use it in GitHub Desktop.
Save thibault/8801077 to your computer and use it in GitHub Desktop.
Rappels de quelques éléments de syntaxe Javascript
// Pour afficher des données
// Popup (pas très propre)
alert('Coucou');
// Affichage sur la console
console.log('Coucou');
// Remplacer le texte d'un Nœud HTML
var node = document.getElementById('node-id');
node.textContent = 'Coucou;
<form id="form-id" method="GET" action="">
<input type="text" id="input-id" />
<input type="submit" value="Go" />
</form>
<script>
var form = document.getElementById('form-id');
var input = document.getElementById('input-id');
form.addEventListener('submit', function (event) {
event.preventDefault();
var value = input.value;
// do something
});
</script>
var add = function(a, b) {
return a + b;
};
var User = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
User.prototype.getFullName = function() {
return this.firstName + ' ' + this.lastName;
};
var user = new User('Test', 'User');
(function(exports) {
var GLOBAL = '...';
var privateMethod = function() {};
var Model = function() {};
exports.Model = Model;
})(this);
var model = new Model();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment