过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
toSource()
method returns a string representing the source code of the object. This method is usually called internally by JavaScript and not explicitly in code. You can call
toSource()
while debugging to examine the contents of an object.
function.toSource();
A string representing the source code of the object.
For the built-in
Function
对象,
toSource()
returns the following string indicating that the source code is not available:
function Function() {
[native code]
}
For custom functions,
toSource()
returns the JavaScript source that defines the object as a string.
// For example:
function hello() {
console.log("Hello, World!");
}
hello.toSource();
// Results in:
"function hello() {
console.log(\"Hello, World!\");
}"
Not part of any standard.
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toSource
非标
|
Chrome No | Edge No |
Firefox
1 — 74
|
IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android 4 | Opera Android No | Safari iOS No | Samsung Internet Android No | nodejs No |
完整支持
不支持
非标。预期跨浏览器支持较差。
见实现注意事项。
Function
Function.prototype.apply()
Function.prototype.bind()
Function.prototype.call()
Function.prototype.toSource()
Function.prototype.toString()
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()