You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
635 B

// Wraps an object-like thing with a proxy to self-bind top-level functions
const bindable = (base_class) => {
return new Proxy(base_class, {
get(target, property) {
// If we're accessing a function of the item, force-bind it
if ( typeof base_class[property] === 'function' && base_class.hasOwnProperty(property) ) {
return base_class[property].bind(base_class)
}
return base_class[property]
},
set(target, property, value) {
base_class[property] = value
}
})
}
// Async sleeper function
const wait = (ms) => {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
export { bindable, wait }