Home > Web Front-end > JS Tutorial > body text

JavaScript method toSource() that represents the source code of an object

黄舟
Release: 2017-11-03 14:06:03
Original
1541 people have browsed it

Definition and usage

toSource() method represents the source code of object.

This primitive value is inherited by all objects derived from the Array object. The

toSource() method is usually called automatically by JavaScript in the background and does not appear explicitly in the code.

Syntax

object.toSource()
Copy after login

Browser support

Only Gecko core browsers (such as Firefox) support this method, which means IE, Safari, Chrome, Opera and other browsers This method is not supported.

Example

The following example shows you the usage of toSource() method:

<script type="text/javascript">

function employee(name,job,born)
{
this.name=name;
this.job=job;
this.born=born;
}

var bill=new employee("Bill Gates","Engineer",1985);

document.write(bill.toSource());

</script>
Copy after login

Output

({name:"Bill Gates", job:"Engineer", born:1985})
Copy after login

Example:

<html>
<head>
<title>JavaScript Array toSource Method</title>
</head>
<body>
<script type="text/javascript">
var arr = new Array("orange", "mango", "banana", "sugar");
 
var str = arr.toSource();
document.write("Returned string is : " + str );
 
</script>
</body>
</html>
Copy after login

This will produce the following result:

Returned string is : ["orange", "mango", "banana", "sugar"]
Copy after login

The above is the detailed content of JavaScript method toSource() that represents the source code of an object. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!