Skip to content

Instantly share code, notes, and snippets.

var xhr = new XMLHttpRequest();
xhr.open('GET', '/my/url'); //xhr.open(method, URL, async, user, password)
xhr.send(); //xhr.send([body])
//xhr.abort() to cancel the request
//also more convenience way to use
//onload onerror events
{ "_id" : ObjectId("56921bc7ae2a196644a46bbd"), "hello" : "mongoShell" }
@qetr1ck-op
qetr1ck-op / 1-sleep-es7.js
Created April 3, 2016 09:19 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()
(function(self) {
'use strict';
if (self.fetch) {
return
}
function normalizeName(name) {
if (typeof name !== 'string') {
name = String(name)
// Factories for creating new btns
// app/components/btnDefaultFactory.js
export default const btnDefaultFactory = (customOpts) => {
const defaultOpts = {
size: 12,
color: 'powderblue',
state: 'brand new'
};
return { ...defaultOpts, ...customOpts };
// Let's get hold of those elements
var outer = document.querySelector('#outer');
var inner = document.querySelector('#inner');
// Let's listen for attribute changes on the
// outer element
new MutationObserver(() => {
console.log('mutate');
}).observe(outer, {
attributes: true
const file1 = getSync('file1.json');
const file2 = getSync('file2.json');
const file3 = getSync('file3.json');
console.log(file1);
console.log(file2);
console.log(file3);
function baz() {
throw new Error('Oops!');
}
function bar() {
return baz();
}
function foo() {
bar();
function multiple(a, b) {
return a * b;
}
function square(n) {
return multiple(n, n);
}
function printSquare(n) {
console.log(square(n));
const o1 = {
prop: 'prop'
}
const o2 = Object.setPrototypeOf({
prop2: 'prop2'
}, o1);
console.log(o2.prop2, o2.prop)