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
// Underscore JS for better "enumerable" functions - underscorejs.org | |
var config = { | |
openOnLoad: false, | |
defaultName: "Jane", | |
options: ["Red", "Green", "Blue"] | |
}; | |
config.options.forEach(function(option){ | |
console.log(option); |
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 config = { | |
openOnLoad: false, | |
defaultName: "Jane", | |
options: ["Red", "Green", "Blue"], | |
print: function() { | |
console.log("Here in config"); | |
} | |
}; | |
console.log(config.print()); // => "Here in config" |
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 jane = { | |
name: "jane", | |
status: "cool" | |
}; | |
function Person(name, status) { | |
this.name = name; | |
this.status = status; | |
this.greeting = function() { | |
console.log("Hello, I'm " + this.name); |
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
$.post( "test.php", $( "#testform" ).serialize() ); |
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
# Each new HTTP request (from client -> server) uses a new TCP/IP connection. | |
# New connection == meeting the the fist time. There's nothing inherent in HTTP that allows a server to remember who is who. | |
# Why would the server need to track miultiple users? | |
# Hacking state onto HTTP ------------ | |
# Tracking 'state' i.e. data |
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').submit( function(e){ | |
e.preventDefault(); | |
var kitten = $(this).serialize(); // sends as string | |
$.ajax({ | |
type: "POST", | |
url: "/kittens/new", | |
data: kitten | |
}) |
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
// How many globals? 4 with console.log | |
function Person(name) { | |
this.name = name; | |
} | |
function greeting(person) { | |
console.log("Hello" + person.name); | |
} |
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
// How do we create scope? | |
function drive() { | |
var innerState = 66; | |
console.log(innerState); // Should print 66 | |
} | |
drive(); //66 | |
console.log(innerState); // Should print undefined or raise not defined |
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
// More than one variable - this is called shadowing | |
var city = "Chicago"; | |
function nyc() { | |
var city = "NYC"; | |
console.log(city); // SHould print "NYC" | |
} | |
nyc(); |
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
// this | |
console.log(this); // window | |
function firstFunction() { | |
console.log("Hello world"); // Hello world | |
console.log(this); //window | |
} | |
function Person(name) { | |
this.name = "Jane Doe"; |