Created
April 17, 2016 23:19
-
-
Save iAmNathanJ/f36fd37551cf52678c5c4a01ba350aff to your computer and use it in GitHub Desktop.
Map all the Math functions to immutable properties directly on another object
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
function addMathTo(obj) { | |
Object.getOwnPropertyNames(Math).forEach((prop) => { | |
let constName = String(prop).toUpperCase(); | |
Object.defineProperty(obj, constName, { | |
value: Math[prop], | |
writable: false, | |
configurable: false | |
}); | |
}); | |
} | |
// USE | |
addMathTo(window); | |
FLOOR(9.5) // => 9 | |
CEIL(9.5) // => 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment