Skip to content

Instantly share code, notes, and snippets.

View no-jquery.js
// JSON
const data = await (await fetch('/my-url')).json();
// Post
await fetch('/my-url', { method: 'POST', body: data });
// Request
try {
const resp = await fetch('/my-url');
// ...
View _onetab_export_markdown.bookmarklet.js
// works on selected text
var selection = window.getSelection().toString();
if (selection) {
selection = selection.match(/[^\r\n]+/g)
.map(function(a) { return "* " + a; }).
join("\n");
prompt("Here's your markdown:", selection);
}
View undefinedParam.js
function hello(name) {
if (typeof name === 'undefined') {
name = 'World';
}
return `Hello ${name}`;
}
console.log(hello());
console.log(hello("Brian"));
View widget-template.js
(function($){
$.widget("ui.mywidget", {
options: {
autoOpen: true
},
_create: function(){
// by default, consider this thing closed.