Skip to content

Instantly share code, notes, and snippets.

@williammalo
Forked from 140bytes/LICENSE.txt
Last active October 2, 2015 09:47
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 williammalo/2221488 to your computer and use it in GitHub Desktop.
Save williammalo/2221488 to your computer and use it in GitHub Desktop.
MathGlobalizr

A function to get rid of the stupid "Math" object once and for all!

It allows this sort of syntax:

 myVariable = floor(myVariable)
 myOtherVariable = random()
function(
a, b //placeholders
)
{
for(b in a = Object.getOwnPropertyNames(Math)) //for every item in the "Math" object
this[a[b]] = Math[a[b]] //set the global item to the math item
}
function(a,b){for(b in a=Object.getOwnPropertyNames(Math))this[a[b]]=Math[a[b]]}
{
"name": "MathGlobalizr",
"description": "A function to get rid of the stupid Math object once and for all!",
"keywords": [
"Math",
"math",
"global",
"simple",
"shorter"
]
}
<!doctype html>
<title>Foo</title>
<div>Expected value: <b>25</b></div>
<div>Actual value: <b id=ret></b></div>
<script>
(
function(a,b){for(b in a=Object.getOwnPropertyNames(Math))this[a[b]]=Math[a[b]]}
)()
document.getElementById("ret").innerHTML = floor(25.64)
</script>​​​​​​​​​​​​​​​​​​​​​​​​​​​​
@williammalo
Copy link
Author

@atk fixd!

@atk
Copy link

atk commented Mar 28, 2012

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment