Skip to content

Instantly share code, notes, and snippets.

@iAmNathanJ
Created April 17, 2016 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iAmNathanJ/f36fd37551cf52678c5c4a01ba350aff to your computer and use it in GitHub Desktop.
Save iAmNathanJ/f36fd37551cf52678c5c4a01ba350aff to your computer and use it in GitHub Desktop.
Map all the Math functions to immutable properties directly on another object
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