1. function as a namespace. form: var Somefn = (function () {var a = 0;return function f () {//...};} ());
2. closures.
Parameters of an external function cannot be accessed directly within a closure unless the external argument is stored as a variable. For example: var outerarguments = arguments;
3. Properties, methods, constructors of functions
A.
Arguments.length; (expected number of arguments passed in)
Arguments.callee.lenth; (number of actual arguments passed in)
B. Prototype properties
Constructors inherit properties and methods from the prototype object;
C. Call () and apply ()
The first parameter is the "parent object to invoke the function"
form: function. Call (object); function. Apply (object);
4. Bind ();--binds the function to the entire object; (returns a Function object)
For example:
function Square (x) {return x*x}; var obj = {X:2}; var newObj = Square.bind (obj,obj.x); Console.log (NEWOBJ()); 4 Note the brackets, because "square.bind (obj,obj.x);" is a function type!!
5. toString ();
6. function (); constructor
A. Pass in any number of string arguments;
B. var fn = new Function ("X", "Y", "return x + y;"); fn (2,3); 5
c. var scope = "global"; function constructfunction () {var scope = "Local"; return new function ("return scope")// None method to obtain local};
7.
201506231015_ "JavaScript authoritative Guide (sixth edition)-functions as namespaces, closures," (p181-193)