Skip to content

Instantly share code, notes, and snippets.

@ungarson
Last active July 21, 2019 06:39
Show Gist options
  • Save ungarson/e58ed106fc0b2f467dd2eb81f9b3596b to your computer and use it in GitHub Desktop.
Save ungarson/e58ed106fc0b2f467dd2eb81f9b3596b to your computer and use it in GitHub Desktop.
Make range object by creating has method in the object's proxy in javascript
let range = {
start: 0,
finish: 10
}
range = new Proxy(range, {
has(target, property) {
if (property >= range.start && range.finish >= property) return true;
else return false;
}
})
export {range};
// Example of usage
// console.log(5 in range); // true
// console.log(20 in range); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment