Skip to content

Instantly share code, notes, and snippets.

View JasonDeving's full-sized avatar

Jason JasonDeving

View GitHub Profile
@JasonDeving
JasonDeving / Revealing_module_pattern
Created March 13, 2016 05:01
javascript revealing module pattern
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script>
window.onload = function () {
calculator.add(2,2);
calculator.subtract(2,2);
}
@JasonDeving
JasonDeving / revealing-prototype-pattern
Created March 13, 2016 06:27
Revealing prototype pattern
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Revealing Prototype Pattern</title>
<script>
window.onload = function () {
var calc = new Calculator('Output');
calc.add(2,2);
calc.subtract(2,2);
@JasonDeving
JasonDeving / forin
Last active March 14, 2016 21:45
javascript - iterations for in loop
var box = {}
box['material'] = "cardboard"
box[0] = 'meow'
box['^&*'] = 'testing 123'
// since var is variable the interpreter hold different properties in bracket notation because key holds the value
for(var key in box) {
console.log(box[key])
}
var animal = {};
animal.username = 'Mittens';
animal['tagline'] = 'pet me';
var noises = [];
animal.noises = noises;
var count = 0;
for(var key in animal) {
count++;
@JasonDeving
JasonDeving / arrays
Created March 15, 2016 05:12
array_access_and_assignment
var box = []
box['size'] = 9;
box['0'] = 'meow';
box['size'] // 9
console.log(box[0]);
// ['meow']
// index # 0
// {0: 'meow', 'size': 9}
var box = []
box['size'] = 9;
box['0'] = 'meow';
for (var k in box){
console.log(k);
// prints out property names
}
for (var k in box){
@JasonDeving
JasonDeving / iterating arrays
Created March 15, 2016 05:47
iterating arrays once more
var box = []
box['size'] = 9; // doesn't return size because it's a string and not integer
box['0'] = 'meow';
box.push("Whoohoo");
for(var i =0; i < 2; i++) {
console.log(box[i]);
}
var box = []
box['size'] = true;
box[3] = {'hey': true};
console.log(box.length);
@JasonDeving
JasonDeving / gist:9be6d1ff914aae4d054b
Created March 16, 2016 04:30
function constructors and looping
// We are creating a constructor
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
},
name: name,
owner: "jason"
};
};
@JasonDeving
JasonDeving / alt-loop
Created March 16, 2016 04:32
loop-through-constructor-with-forEach
function AnimalMaker(name) {
return {
speak: function () {
console.log("my name is ", name);
},
name: name,
owner: "jason"
};
};