Niestandardowy
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
Podsumowanie
Zwraca literał obiektowy reprezentujący kod źródłowy danego obiektu.
Składnia
Object.toSource();
obj.toSource();
Parametry
Brak.
Opis
Metoda toSource() zwraca następujące wartości:
- dla obiektu wbudowanego
ObjectmetodatoSource()zwraca następujący ciąg znaków, wskazujący na niedostępność kodu źródłowego:function Object() { [native code] } - dla instancji
ObjectmetodatoSource()zwraca ciąg reprezentujący ich kod źródłowy.
Metoda ta zazwyczaj jest używana wewnętrznie przez interpreter JavaScriptu, a nie bezpośrednio w kodzie. Można jednak wywołać toSource() podczas debugowania, by zbadać zawartość danego obiektu.
Przykłady
Przykład: Zastosowanie toSource()
Poniższy kod definiuje typ obiektowy Pies i tworzy instancję piesek jako obiekt typu Pies:
functionPies(nazwa) { this.nazwa=nazwa; }Pies.prototype.toSource = functionPies_toSource() { return 'newPies(' + uneval(this.nazwa) + ')'; }; console.log(newPies('Joe').toSource()); // ---> newPies("Joe")
Zobacz także
Array.prototype.toSource()—ArrayObject method.Boolean.prototype.toSource()—BooleanObject method.Date.prototype.toSource()—DateObject method.Function.prototype.toSource()—FunctionObject method.Number.prototype.toSource()—NumberObject method.Regexp.prototype.toSource()—RegExpObject method.String.prototype.toSource()—StringObject method.Symbol.prototype.toSource()—SymbolObject method.Math.toSource()— Returns the String "Math".