Skip to content

Instantly share code, notes, and snippets.

@cjfswd
Last active May 23, 2022 21:23
Show Gist options
  • Save cjfswd/25571a2844203672dad5d9227706b003 to your computer and use it in GitHub Desktop.
Save cjfswd/25571a2844203672dad5d9227706b003 to your computer and use it in GitHub Desktop.
javascript snippets
// change replace all of substring
str.replace(/foo/g, "bar")
// destructuring: remove attribute and create new object
const { json, ...withoutJson } = data
// get blob from any path or url
const getBlob = async (path: string) => {
return fetch(path).then(res => res.blob())
}
// method chaining
const dog = {
is: null,
log: () => console.log(this.is),
bark() {
this.is = "woofing";
this.log();
return this;
},
walk() {
this.is = "walking";
this.log();
return this;
},
eat() {
this.is = "eating";
this.log();
return this;
}
};
dog
.bark()
.eat()
.walk();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment