Last active
April 21, 2017 09:54
-
-
Save thibault/8801077 to your computer and use it in GitHub Desktop.
Rappels de quelques éléments de syntaxe Javascript
This file contains 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
// 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; |
This file contains 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
<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> |
This file contains 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
var add = function(a, b) { | |
return a + b; | |
}; |
This file contains 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
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'); |
This file contains 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(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