From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../global_objects/function/tostring/index.html | 130 +++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 files/es/web/javascript/reference/global_objects/function/tostring/index.html (limited to 'files/es/web/javascript/reference/global_objects/function/tostring') diff --git a/files/es/web/javascript/reference/global_objects/function/tostring/index.html b/files/es/web/javascript/reference/global_objects/function/tostring/index.html new file mode 100644 index 0000000000..b5ee70147e --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/function/tostring/index.html @@ -0,0 +1,130 @@ +--- +title: Function.prototype.toString() +slug: Web/JavaScript/Referencia/Objetos_globales/Function/toString +translation_of: Web/JavaScript/Reference/Global_Objects/Function/toString +--- +
{{JSRef}}
+ +

El método toString() retorna una cadena representando el código fuente de la función.

+ +

Sintaxis

+ +
function.toString(indentation)
+ +

Parámetros

+ +
+
indentation {{non-standard_inline}} {{obsolete_inline(17)}}
+
La cantidad de espacios a indentar en la representación de cadena del código fuente. Si indentation es menor o igual a -1, la mayoría de los espacios innecesarios son eliminados.
+
+ +

Descripción

+ +

El objeto {{jsxref("Function")}} reconduce el método {{jsxref("Object.prototype.toString", "toString")}} heredado de  {{jsxref("Object")}}; no hereda {{jsxref("Object.prototype.toString")}}. Para objetos {{jsxref("Function")}}, el método toString retorna una representación de cadena del objeto en forma de declaración de función. Esto es, toString descompila la función y la cadena retornada incluye la palabra clave function, la lista de argumentos, llaves y el código fuente del cuerpo de la función.

+ +

JavaScript llama al método toString automáticamente cuando una {{jsxref("Function")}} va a ser representada como un valor de texto, p.e. cuando una función es concatenada con un valor de cadena (string).

+ +

El método toString() producirá una excepción {{jsxref("TypeError")}} ("Function.prototype.toString called on incompatible object"), si el valor de su objeto this no es un objeto Function. Esto también ocurrirá para objetos {{jsxref("Proxy")}}, por ejemplo:

+ +
Function.prototype.toString.call("foo"); // TypeError
+
+var proxy = new Proxy(function() {}, {});
+Function.prototype.toString.call(proxy); // TypeError
+
+ +

Especificaciones

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EspecificaciónEstadoObservaciones
{{SpecName('ES1')}}{{Spec2('ES1')}}Definición inicial. Implementado en JavaScript 1.1.
{{SpecName('ES5.1', '#sec-15.3.4.2', 'Function.prototype.toString')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-function.prototype.tostring', 'Function.prototype.toString')}}{{Spec2('ES6')}}Añadidos requerimientos más específicos para la representación de cadena.
{{SpecName('ESDraft', '#sec-function.prototype.tostring', 'Function.prototype.toString')}}{{Spec2('ESDraft')}} 
+ +

Compatibilidad con navegadores

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
PrestaciónChromeFirefox (Gecko)Internet ExplorerOperaSafari
Soporte básico{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
PrestaciónAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Soporte básico{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Notas específicas para Gecko

+ + + +

Ver también

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