-
Book Overview & Buying
-
Table Of Contents
Object-Oriented JavaScript
JavaScript functions are objects. They can be defined using the Function constructor, like so:
>>> var sum = new Function('a', 'b', 'return a + b;'); This is equivalent to the function literal:
>>> var sum = function(a, b){return a + b;};or the more common:
>>> function sum(a, b){return a + b;}The use of the Function constructor is discouraged in favor of the function literals.
|
Property/Method |
Description |
|---|---|
|
|
Allows you to call another function while overwriting its function whatIsIt(){
return this.toString();
}
>>> var myObj = {};
>>> whatIsIt.apply(myObj);
"[object Object]" >>> whatIsIt.apply(window); "[object Window]" |
|
|
Same as |
|
|
The number of parameters the function expects. >>> alert.length 1 >>> parseInt.length 2 |
Change the font size
Change margin width
Change background colour