Last active
May 23, 2022 21:23
-
-
Save cjfswd/25571a2844203672dad5d9227706b003 to your computer and use it in GitHub Desktop.
javascript snippets
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
// 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