| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Function/toString | [Back] [Original] |
Get to know MDN better
Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.
This feature is well established and works across many devices and browser versions. Its been available across browsers since julio de 2015.
El mtodo toString() retorna una cadena representando el cdigo fuente de la funcin.
function.toString(indentation)
indentation La cantidad de espacios a indentar en la representacin de cadena del cdigo fuente. Si indentation es menor o igual a -1, la mayora de los espacios innecesarios son eliminados.
El objeto Function reconduce el mtodo toString heredado de Object; no hereda Object.prototype.toString. Para objetos Function, el mtodo toString retorna una representacin de cadena del objeto en forma de declaracin de funcin. Esto es, toString descompila la funcin y la cadena retornada incluye la palabra clave function, la lista de argumentos, llaves y el cdigo fuente del cuerpo de la funcin.
JavaScript llama al mtodo toString automticamente cuando una Function va a ser representada como un valor de texto, p.e. cuando una funcin es concatenada con un valor de cadena (string).
El mtodo toString() producir una excepcin TypeError ("Function.prototype.toString called on incompatible object"), si el valor de su objeto this no es un objeto Function. Esto tambin ocurrir para objetos Proxy, por ejemplo:
Function.prototype.toString.call("foo"); // TypeError
var proxy = new Proxy(function () {}, {});
Function.prototype.toString.call(proxy); // TypeError
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-function.prototype.tostring |
This page was last modified on 5 ago 2023 by MDN contributors.
FunctionObject/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |