Java Reference
In-Depth Information
that takes two parameters and returns the result of applying the
+
operator on both
arguments. Calling
adder(10, 20)
will return 30:
var adder = new Function("p1", "p2", "return p1 + p2");
Function.prototype
is an object that itself is a
Function
object.
Function.
prototype
is set as the prototype object for all functions you create. So, all properties
available in
Function.prototype
are available in all functions. The following properties
are defined in
Function.prototype
:
•
Function.prototype.constructor
•
Function.prototype.toString()
•
Function.prototype.apply(thisArg, argArray)
•
Function.prototype.call(thisArg, arg1, arg2,...)
Function.prototype.bind(thisArg, arg1, arg2,...)
The
Function.prototype.constructor
property is set to the built-in
Function
constructor.
The
Function.prototype.toString()
method returns an implementation-
dependent representation of the function object. The following code shows how to use
this method and the values it returns for different types of object. Note that for the
user-defined functions, it returns the function declaration as a string and for built-in
function the body of the function is returned as
[native code]
:
•
function adder(n1, n2) {
return n1 + n2;
}
// Call the toString() method of the user-defined adder function
var adderStr = adder.toString();
// Call the toString() method of the built-in print function
var printStr = print.toString;
print("adderStr: \n" + adderStr);
print("printstr:\n" + printStr);
adderStr:
function adder(n1, n2) {
return n1 + n2;
}
printstr:
function toString() { [native code] }
Search WWH ::
Custom Search