-
Book Overview & Buying
-
Table Of Contents
Object-Oriented JavaScript
This Appendix contains a list of the built-in functions (methods of the global object), discussed in Chapter 3.
|
Function |
Description |
|---|---|
|
|
Takes two parameters: an input object and radix; then tries to return an integer representation of the input. Doesn't handle exponents in the input. The default radix is >>> parseInt('10e+3')
10 >>> parseInt('FF')
NaN >>> parseInt('FF', 16)
255 |
|
|
Takes a parameter and tries to return a floating-point number representation of it. Understands exponents in the input. >>> parseFloat('10e+3')
10000 >>> parseFloat('123.456test')
123.456 |
|
|
Abbreviated from "Is Not a Number". Accepts a parameter and returns >>> isNaN(NaN) true >>> isNaN(123) false >>> isNaN(parseInt('FF'))
true >>> isNaN(parseInt('FF', 16))
false |
|
|
Returns >>> isFinite(1e+1000) false >>> isFinite(-Infinity) false >>> isFinite("123")
true |
|
|
Converts the input into a URL-encoded string. For more details on how URL encoding works, consult the Wikipedia article: http://en.wikipedia.org/wiki/Url_encode >>>encodeURIComponent('http://phpied.com/')
"http%3A%2F%2Fphpied.com%2F" >>> encodeURIComponent('some script?key=v@lue')
"some%20script%3Fkey%3Dv%40lue" |
|
|
Takes an URL-encoded string and decodes it. >>> decodeURIComponent('%20%40')
" @" |
|
|
URL-encodes the input, but assumes a full URL is given, so returns a valid URL by not encoding the protocol (for example >>> encodeURI('http://phpied.com/')
"http://phpied.com/" >>> encodeURI('some script?key=v@lue')
"some%20script?key=v@lue" |
|
|
Opposite of >>> decodeURI("some%20script?key=v@lue")
"some script?key=v@lue" |
|
|
Accepts a string of JavaScript code and executes it. Returns the result of the last expression in the input string. To be avoided where possible. >>> eval('1+2')
3 >>> eval('parseInt("123")')
123 >>> eval('new Array(1,2,3)')
[1, 2, 3] >>> eval('new Array(1,2,3); 1+1;')
2 |
Change the font size
Change margin width
Change background colour