Dokumentacja języka JavaScript 1.5:Obiekty:Function
z Mozilla Developer Center, polskiego centrum programistów Mozilli.
UWAGA: Tłumaczenie tej strony nie zostało zakończone.
Może być ona niekompletna lub wymagać korekty.
Chcesz pomóc? | Dokończ tłumaczenie | Sprawdź ortografię | Więcej takich stron...
- This page documents the use of the
Functionobject itself and its use as a constructor. For a list of properties and methods inherited byFunctioninstances, see Function.prototype.
Spis treści |
[edytuj] Podsumowanie
Every function in JavaScript is actually a Function object.
[edytuj] Składnia
new Function ([arg1[, arg2[, ... argN]],] functionBody)
[edytuj] Parametry
-
arg1, arg2, ... argN - Names to be used by the function as formal argument names. Each must be a string that corresponds to a valid JavaScript identifier or a list of such strings separated with a comma; for example "
x", "theValue", or "a,b".
-
functionBody - A string containing the JavaScript statements comprising the function definition.
Invoking the Function constructor as a function (without using the new operator) has the same effect as invoking it as a constructor.
[edytuj] Opis
Function objects created with the Function constructor are evaluated each time they are used. This is less efficient than declaring a function and calling it within your code, because declared functions are parsed only once.
All arguments passed to the function are treated as the names of the identifiers of the parameters in the function to be created, in the order in which they are passed.
[edytuj] Własności
- prototype
- Allows the extension of all
Functionobjects.
Properties dziedziczone z Function.prototype
caller, constructor, length, name
[edytuj] Metody
Although the Function object does not provide any methods of its own, it does inherit methods through the prototype chain.
Methods dziedziczone z Object.prototype
__defineGetter__, __defineSetter__, hasOwnProperty, isPrototypeOf, __lookupGetter__, __lookupSetter__, __noSuchMethod__, propertyIsEnumerable, unwatch, watch
[edytuj] Przykłady
[edytuj] Przykład: Specifying arguments with the Function constructor
The following code creates a Function object that takes two arguments.
var multiply = new Function("x", "y", "return x * y");
var theAnswer = multiply(7, 6);
The arguments "x" and "y" are formal argument names that are used in the function body, "return x * y".
[edytuj] Zobacz także
- Operator function
- Polecenie function
- [[[Core JavaScript 1.5 Reference:Functions|Functions]]