Skip to content

Instantly share code, notes, and snippets.

@rodukov
Last active June 16, 2023 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodukov/439a96d012ac23736b822d376c3b6b62 to your computer and use it in GitHub Desktop.
Save rodukov/439a96d012ac23736b822d376c3b6b62 to your computer and use it in GitHub Desktop.
Senior JavaScript Things
const person1 = {"name": "Michael", age: 25}
const person2 = {"name": "Kate", age: 23 }
function log() {
console.log(this.name, this.age)
}
function bind(ctx, fn) {
return function(...args) {
fn.apply(context, args)
}
}
const sleep = sec => new Promise(resolve => setTimeout(() => resolve(sec), sec*1000))
sleep(3).then(sec => console.log(`Executed after ${sec} seconds`))
/* Promise.all([sleep(1), sleep(2), sleep(3)]).then(data => console.log(data)) */
/* Promise.race([sleep(1), sleep(2), sleep(3)]).then(data => console.log(data)) */
/* Function injections to Object Global Class */
Object.prototype.keyslength = () => Object.keys(s).length
Object.prototype.valueslength = () => Object.values(s).length
/* Custom injections to custom object */
const keyslength = () => Object.keys(s).length
const valueslength = () => Object.values(s).length
let custom_object1 = Object.create(keyslength)
let custom_object2 = Object.create(valueslength)
const array = [1, 2, 3, 4, 5]
Array.prototype.mult(n) {
return this.map((i) => {i * n})
}
array.multBy(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment