From 4b1a9203c547c019fc5398082ae19a3f3d4c3efe Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:15 -0500 Subject: initial commit --- .../global_objects/function/caller/index.html | 124 +++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 files/ca/web/javascript/reference/global_objects/function/caller/index.html (limited to 'files/ca/web/javascript/reference/global_objects/function/caller/index.html') diff --git a/files/ca/web/javascript/reference/global_objects/function/caller/index.html b/files/ca/web/javascript/reference/global_objects/function/caller/index.html new file mode 100644 index 0000000000..613e163d6a --- /dev/null +++ b/files/ca/web/javascript/reference/global_objects/function/caller/index.html @@ -0,0 +1,124 @@ +--- +title: Function.caller +slug: Web/JavaScript/Reference/Global_Objects/Function/caller +translation_of: Web/JavaScript/Reference/Global_Objects/Function/caller +--- +
{{JSRef}} {{non-standard_header}}
+ +

La propietat function.caller retorna la funció que ha invocat la funció especificada.

+ +

Descripció

+ +

SI la funció f ha estat invocada pel codi de nivell superior, el valor de f.caller és {{jsxref("null")}}, sinó és la funció que ha cridat f.

+ +

Aquesta propietat reemplaça la propietat obsoleta {{jsxref("Functions/arguments/caller", "arguments.caller")}} de l'objecte {{jsxref("Functions/arguments", "arguments")}}.

+ +

La propietat especial __caller__, la qual retorna l'objecte activatwhich returned the activation object of the caller thus allowing to reconstruct the stack, was removed for security reasons.

+ +

Notes

+ +

Vegeu que en cas de recursió, no podeu reconstruir la pila de crida fent servir aquesta propietat. C that in case of recursion, you can't reconstruct the call stack using this property. Tingueu en compte:

+ +
function f(n) { g(n - 1); }
+function g(n) { if (n > 0) { f(n); } else { stop(); } }
+f(2);
+
+ +

At the moment stop() is called the call stack will be:

+ +
f(2) -> g(1) -> f(1) -> g(0) -> stop()
+
+ +

El següent és cert:

+ +
stop.caller === g && f.caller === g && g.caller === f
+
+ +

so if you tried to get the stack trace in the stop() function like this:

+ +
var f = stop;
+var stack = 'Stack trace:';
+while (f) {
+  stack += '\n' + f.name;
+  f = f.caller;
+}
+
+ +

El bucle mai s'aturaria.

+ +

Exemples

+ +

Checking the value of a function's caller property

+ +

El codi següent comprova que el valor following code checks the value a function's caller property.

+ +
function myFunc() {
+  if (myFunc.caller == null) {
+    return 'The function was called from the top!';
+  } else {
+    return 'This function\'s caller was ' + myFunc.caller;
+  }
+}
+
+ +

Especificacions

+ +

No forma part de cap especificació. Implementat en JavaScript 1.5.

+ +

Compatibilitat amb navegadors

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatGeckoDesktop("1.0")}}8.0{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatGeckoMobile("1.0")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Vegeu també

+ + -- cgit v1.2.3-54-g00ecf