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
// http://ejohn.org/blog/objectgetprototypeof/ | |
function instanceOf(object, constructor) { | |
while (object != null) { | |
if (object == constructor.prototype) { | |
return true; | |
} | |
object = Object.getPrototypeOf(object); | |
} | |
return false; | |
} |
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
// == PARENT =================================================================== | |
// CONSTRUCTOR | |
// For this demo we'll be inheriting from the Parent class | |
function Parent() {} | |
// METHODS | |
Parent.prototype.foo = function foo() { | |
return 'FOO'; | |
} |
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
javascript: { | |
/* Adjust voice speed. Default = 1 */ | |
var speed = 2.5; | |
if (window.runTTS === undefined) { | |
/* Text to Speech function. Adjust the value of msg.rate to increase/decrease the playback speed. */ | |
window.runTTS = () => { | |
const text = window.getSelection().toString(); | |
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
let sourceObject = { foo: { bar: { baz: { qux: { value: "Hit!" } } } } }; | |
sourceObject.foo[Symbol.for('symbol')] = 'symbol value'; | |
function lookup(object, path) { | |
path = Array.isArray(path) ? path : path.split('.'); | |
for(let i = 0; i < path.length; i++) { | |
object = object[path[i]]; | |
if (!object) break; |
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
(function exposeNgUtil(target = window) { | |
if (!angular) { | |
console.error(`ERROR: ng-util cannot initialize because "angular" was not found!`); | |
return null; | |
} | |
getScope = el => angular.element( (el || document.getElementsByClassName('ng-scope')[0]) ) | |
let ngUtils = { | |
// Use Angular.js' DI system to retrieve a provider. |
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
// http://www.ecma-international.org/ecma-262/6.0/#sec-symbol.toprimitive | |
let base = { | |
[Symbol.toPrimitive] : hint => { | |
console.log(`toPrimitive hint: ${hint}`) | |
return 1; | |
}, | |
valueOf: () => 2, | |
toString: () => '3', | |
}; |
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
// Resources | |
// | |
// - http://exploringjs.com/es6/ch_proxies.html | |
// - https://github.com/tvcutsem/harmony-reflect/issues/41 | |
// - https://esdiscuss.org/topic/proxies-stratifying-tostring-valueof | |
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | |
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive | |
// - https://console.spec.whatwg.org/#inspection | |
// NOTE: When Chrome logs "Symbol(Symbol.toPrimitive)", that corisponds to |
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
// ==================== | |
// = OBJECT HELPERS = | |
// ==================== | |
export const set = (obj, prop, val) => { | |
obj[prop] = val | |
return obj | |
} | |
export const extractObj = (obj, prop) => | |
Object.keys(obj).map(key => |
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
// Open http://reactivex.io/rxjs/manual/overview.html to run this code | |
var timer = new Rx.Observable((obs) => { | |
var counter = 0; | |
var int = setInterval(() => obs.next(++counter), 1000); | |
return () => { | |
clearInterval(int); | |
obs.complete(); | |
} | |
}); |
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
const VOID = Symbol('VOID'); | |
class LinkedItem { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class LinkedList { |