Last active
May 9, 2017 22:00
-
-
Save jshcrowthe/1da65116d46bd4fa4618c3054c7792f1 to your computer and use it in GitHub Desktop.
Iterable ClientRects
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
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