Skip to content

Instantly share code, notes, and snippets.

@jshcrowthe
Last active May 9, 2017 22:00
Show Gist options
  • Save jshcrowthe/1da65116d46bd4fa4618c3054c7792f1 to your computer and use it in GitHub Desktop.
Save jshcrowthe/1da65116d46bd4fa4618c3054c7792f1 to your computer and use it in GitHub Desktop.
Iterable ClientRects
ClientRect.prototype[Symbol.iterator] = function() {
// ClientRect's properties apparently can't be discovered with Object.keys :(
const obj = Object.assign({}, {
top: this.top,
right: this.right,
bottom: this.bottom,
left: this.left,
height: this.height,
width: this.width,
});
const keys = Object.keys(obj);
let idx = 0;
return {
next: function() {
if (idx < keys.length) {
return { value: obj[keys[idx++]], done: false };
} else {
return { done: true };
}
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment