Skip to content

Instantly share code, notes, and snippets.

jesperorb / closure-vs-class.ts
Last active Oct 17, 2022
Closure callback vs Class
View closure-vs-class.ts
type Status = "COMPLETE" | "PENDING" | "ERROR";
type Transaction = {
id: string;
status: Status
const transactions: Transaction[] = [
id: "gghf",
View snippets.code-snippets
"console.log()": {
"prefix": "cl",
"body": [
"description": "console.log()"
"": {
"prefix": "cg",
View alternateCasing.js
function alternateCasing(text){
let letters ≈ ''
for (const index in text) {
if(index % 2) {
letters += text[index].toLowerCase()
} else {
letters += text[index].toUpperCase()
jesperorb / html-string-vs-createElement.js
Last active Mar 1, 2022
Pros and cons using .insertAdjacentHTML vs .createElement
View html-string-vs-createElement.js
* There is a pro to using document.createElement() instead of just applying a
* string to the page that gets converted to HTML. When we use the pure string method
* we do not get a link/reference to the actual element that is seen on the page. This
* usually means we have to get the element again to modify it. For example, add an event
* listener
// .createElement() + .addEventListener()
jesperorb /
Last active May 10, 2018
Different prototype patterns

Constructor Pattern

//Constructor pattern, a function that produces new
//objects. But still just a regular function
function Person(name, age){ = name;
    this.age = age;
jesperorb /
Last active Nov 21, 2021
Kom igång med Module Bundlers (Parcel & Webpack)

Module Bundler (Parcel & Webpack)

Node & require

I Node.js finns ingen index.html som binder samman alla våra resurser (.js, .css etc.) men vi måste ändå ha ett sätt att kommunicera mellan filer på ett enkelt sätt. Detta löser node med att man exporterar och importerar explicit från varje fil, liknande som sass förutom att här måste vi även vara explicit med vad vi exporterar. Vi kan även välja att inte exportera allting i filen så vissa variabler kan vara "privata" till själva filen medan andra kan vara "publika" för resten av dina filer.

const person = require('./person.js');
// const { name, age } = require('./person'); //destructure
jesperorb /
Last active Dec 20, 2022
PHP form submitting with fetch + async/await

PHP Form submitting

If we have the following structure in our application:

  • 📁 application_folder_name
    • 📄 index.php
    • 📄 handle_form.php
    • 📄 main.js

And we fill our index.php with the following content just to get a basic website with a form working. You should be able to run this through a php-server of your choice.

jesperorb / XMLHttpRequest.js
Created Feb 22, 2018
XMLHttpRequest example
View XMLHttpRequest.js
/* We create a new request-object that will handle the transaction between the server/database
* and the client (me/us/the browser). */
var request = new XMLHttpRequest();
* We add a listener to the request which will listen to when the state changes,
jesperorb /
Last active Aug 31, 2017
Common Errors in React

Common Errors in React

Unterminated JSX Content

Don't focus on which element the cursor is pointing, just look for any element that hasn't been closed


Unterminated JSX Content


jesperorb /
Last active Mar 1, 2021
Examples of how to bind functions in React

Binding In React

this and binding in JavaScript

To properly use react you need to get a good understanding about binding and the keyword this in regular JavaScript. When adding a function to an event i JavScript you don't call the