This file contains hidden or 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 Node(data) { | |
this.data = data; | |
this.next = null; | |
} | |
function LinkedList() { | |
this.head = null; | |
} | |
LinkedList.prototype.addNode = function(node) { |
This file contains hidden or 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
// 1 - Implicit binding | |
// 2 - Explicit binding | |
// 3 - new binding | |
// 4 - window binding | |
// new Binding | |
// this is bound to the new object being constructed | |
var Animal = function(color, name, type) { | |
//this = {}; JS does this automatically for us behind the scenes. | |
this.color = color; |
This file contains hidden or 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
// Explicit Binding | |
// call, apply, bind | |
// these methods allow you to explicitly state what the 'this' keyword is going to be in any given function | |
// Example 1 | |
var sayName = function(lang1, lang2, lang3) { | |
console.log('My name is ' + this.name + ' and I know ' + lang1 + ', ' + lang2 + ', and ' + lang3); | |
}; | |
var stacy = { |
This file contains hidden or 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
// Implicit Binding | |
// Left of the dot at call time | |
// Ask yourself... | |
// where is this function invoked? | |
// Example 1 | |
var me = { | |
name: 'Nate', | |
age: 25, |
This file contains hidden or 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
// Demonstrates a few ways to achieve OOP with JavaScript | |
// Solution 1 | |
function playerCreator(name, score) { | |
var newPlayer = Object.create(playerFunctionStore); | |
newPlayer.name = name; | |
newPlayer.score = score; | |
return newPlayer; | |
} |
This file contains hidden or 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 display({data, error, loading}) { | |
if (loading) { | |
return "Loading..."; | |
} | |
if (error) { | |
return error.message; | |
} | |
return `Hello ${data.name}`; | |
} |
This file contains hidden or 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 people = (function() { | |
var people = ['Will', 'Matt']; | |
// Cache Dom | |
$el = $('#peopleModule'); | |
$button = this.$el.find('button'); | |
$input = this.$el.find('input'); | |
$ul = this.$el.find('ul'); | |
template = this.$el.find('#people-template').html(); | |
This file contains hidden or 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() { | |
var people = { | |
people: ['Will', 'Matt'], | |
template: $('#people-template').html(), | |
init: function() { | |
this.cacheDom(); | |
this.bindEvents(); | |
this.render(); | |
}, |
This file contains hidden or 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
// Observer Pattern | |
// Inspired by: https://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript | |
var Subject = function() { | |
let observers = []; | |
const publicAPI = { | |
subscribeObserver: function(observer) { | |
observers.push(observer); |
This file contains hidden or 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
// Singleton Pattern | |
// Inspired by: https://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript | |
var mySingleton = (function () { | |
// Instance stores a reference to the Singleton | |
let instance; | |
function init() { | |
NewerOlder