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 LinkedList() { | |
if (!(this instanceof LinkedList)) { | |
throw new TypeError('"LinkedList" cannot be called as a function. Use the "new" keyword to construct a new "LinkedList" object'); | |
} | |
this._head = undefined; | |
} | |
LinkedList.prototype = { | |
clear: function () { |
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
// The following is a proof of concept for creating Map and Set data structures found in ES2015 | |
// URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | |
// URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set | |
function Map(iterable) { | |
if (!(this instanceof Map)) { | |
throw new TypeError('"Map" cannot be called as a function. Use the "new" keyword to construct a new "Map" object'); | |
} | |
this._keys = []; |
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 on = _createEvent.bind(null, 'on'); | |
var remove = on(document, 'click', 'body', function (event, target) { | |
// "this" is set to the target element node | |
console.log('On::', this, event, target); | |
}); | |
var once = _createEvent.bind(null, 'once'); | |
once(document, 'click', 'body', function (event, target) { | |
// "this" is set to the target element node | |
console.log('Once::', this, event, target); |
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 DOM(selector) { | |
if (!(this instanceof DOM)) { | |
return new DOM(selector); | |
} | |
// Helper for pushing an array-like object onto the current instance | |
Array.prototype.push.apply(this, document.querySelectorAll(selector)); | |
} | |
_inheritFrom(DOM, Array); |
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 ArrayObject(arr) { | |
arr.forEach((value, index) => { | |
this[index] = value; | |
}); | |
this.guid = 'RANDOM_ARRAY_LIKE_GUID_' + Math.floor(Math.random() * 9999); | |
// Create an immutable length property | |
Object.defineProperty(this, 'length', { | |
value: arr.length |
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
// Idea 1: http://www.datchley.name/promise-patterns-anti-patterns/ | |
// good | |
good(); | |
function good() { | |
// getJSON returns a promise, so just continue the chain | |
return getJSON() | |
.then(function (artists) { | |
// Map the array of artists to an array of names |
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
// Idea 1: https://www.promisejs.org/generators/ | |
// Idea 2: http://bluebirdjs.com/docs/api/promise.coroutine.html | |
const asyncDemo = Promise.coroutine(function* () { | |
try { | |
const res = yield getJSON() | |
console.log(res.value) | |
} catch (err) { | |
console.log(err) | |
} |
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
// Idea 1: https://medium.com/@bluepnume/learn-about-promises-before-you-start-using-async-await-eb148164a9c8#.s6914ps6a | |
// Use: https://babeljs.io/repl/ to transpile as ES5 | |
async function asyncDemo() { | |
try { | |
const res = await getJSON() // Promise.all([getJSON(), getJSON()]) for concurrent requests | |
console.log(res.value) | |
} catch (err) { | |
console.log(err) | |
} |
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
<?php | |
// Prevent content sniffing attacks such as http://mths.be/bst. | |
header('X-Content-Type-Options: nosniff'); | |
// Note: The user-provided callback name must be filtered to prevent attack | |
// vectors. This script simply removes any symbols other than `[a-zA-Z0-9$_]` | |
// from the input. Sadly, this blocks the use of some valid JavaScript | |
// identifiers, and also accepts a few invalid ones. See | |
// http://mathiasbynens.be/notes/javascript-identifiers for details. |
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 dom = (function dom(window, document) { | |
// Based on the idea of jQuery 3 | |
var _resolveReady; | |
var _isReady = false; | |
var _listReady = new window.Promise(function promiseReady(resolve) { | |
_resolveReady = resolve; | |
}); | |
// Check if the DOM has completed loading or is not in a loading state | |
if (document.readyState === 'complete' || document.readyState !== 'loading') { |