On Github sdvf / javascript-presentation
Created by Santiago Villa Fernandez / @sdemians
It is really easy.
Download and install google chrome :-P
// bad
var item = new Object();
// good
var item = {
name : "myName",
data : {var1 : 1, var2 : 2}
};
var example; var pi=3.14; var person='John Doe'; var lastname='Doe', age=30, job='carpenter';
// anonymous function expression
var anonymous = function() {
return true;
};
// named function expression
var named = function named() {
return true;
};
// immediately-invoked function expression (IIFE)
(function() {
console.log('Welcome to the Internet. Please follow me.');
})();
//Use the literal syntax for array creation // bad var items = new Array(); // good var items = [];
var someStack = [];
// bad
someStack[someStack.length] = 'abracadabra';
// good
someStack.push('abracadabra')
/**
* A base class
*/
function A() {
this.type = "A type";
}
A.prototype.toString = function() {
return "Transform";
}
/**
* B class.
*/
function B(x, y) {
// Parent constructor
A.call(this);
// Public properties
this.x = x;
this.y = y;
}
B.prototype = Object.create(B.prototype);
B.prototype.toString = function() {
return A.prototype.toString() + this.type + " B " + this.x + ":" + this.y;
}
// Tests var b = new B(10, 15); console.log(b instanceof A); // true console.log(b instanceof B); // true
<script type="text/javascript">
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "ajax_info.txt", true);
xmlhttp.send();
}
</script>
$.ajax({
url: "/api/getWeather",
data: {
zipcode: 97201
},
success: function( data ) {
$( "#weather-temp" ).html( "<strong>" + data + "</strong> degrees" );
}
});