Skip to content

Instantly share code, notes, and snippets.

View nealfennimore's full-sized avatar
:shipit:
RGlkIHlvdSBhbHNvIGRlY29kZSB0aGlzPw==

Neal Fennimore nealfennimore

:shipit:
RGlkIHlvdSBhbHNvIGRlY29kZSB0aGlzPw==
View GitHub Profile
@nealfennimore
nealfennimore / javascript_each_loop.js
Created April 22, 2014 16:15
Javascript Each Loop
// 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);
@nealfennimore
nealfennimore / console_log_and_object_calls.js
Last active August 29, 2015 14:00
Console Log and Object Calls
var config = {
openOnLoad: false,
defaultName: "Jane",
options: ["Red", "Green", "Blue"],
print: function() {
console.log("Here in config");
}
};
console.log(config.print()); // => "Here in config"
@nealfennimore
nealfennimore / contructor_functions.js
Created April 22, 2014 16:55
Constructor Functions
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);
$.post( "test.php", $( "#testform" ).serialize() );
# 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
$('form').submit( function(e){
e.preventDefault();
var kitten = $(this).serialize(); // sends as string
$.ajax({
type: "POST",
url: "/kittens/new",
data: kitten
})
@nealfennimore
nealfennimore / global_variables_javascript.js
Created April 30, 2014 14:40
Global Variables Javascript
// How many globals? 4 with console.log
function Person(name) {
this.name = name;
}
function greeting(person) {
console.log("Hello" + person.name);
}
@nealfennimore
nealfennimore / creating_scope_javascript.js
Created April 30, 2014 14:43
Creating Scope Javascript
// 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
@nealfennimore
nealfennimore / more_than_one_variable_javascript.js
Created April 30, 2014 14:55
More than one variable Javascript
// More than one variable - this is called shadowing
var city = "Chicago";
function nyc() {
var city = "NYC";
console.log(city); // SHould print "NYC"
}
nyc();
@nealfennimore
nealfennimore / always_a_this_javascript.js
Created April 30, 2014 14:58
Always a This Javascript
// this
console.log(this); // window
function firstFunction() {
console.log("Hello world"); // Hello world
console.log(this); //window
}
function Person(name) {
this.name = "Jane Doe";