Look at the results of various forms of functions in script

Source: Internet
Author: User

Example 1:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566,
Fullname:function ()
{
return this.firstname + "" + this.lastname;
}
};
document.getElementById ("Demo"). InnerHTML = Person.fullname ();
</script>

</body>

Example 1 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

John Doe


Example 2:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is a function definition and is stored as a property value. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566,
Fullname:function ()
{
return this.firstname + "" + this.lastname;
}
};
document.getElementById ("Demo"). InnerHTML = Person.fullname;
</script>

</body>

Example 2 results:
Create and use object methods.

An object method is a function definition and is stored as a property value.

function () {return this.firstname + "" + This.lastname;}


Example 3:
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566,
}
function FullName () {
return person.firstname + "" +person.lastname;
}
FullName (); there is no output for this sentence because there is no output value in the FullName function
function FullName2 () {
document.write (Person.firstname + person.lastname);
}
document.getElementById ("Demo"). InnerHTML =fullname ();//This sentence is used in conjunction with the FullName function
FullName2 ();//Call Function fullName2
</script>

</body>


Example 3 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

John Doe

John doe

Example 4:
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566,
}
function FullName () {
return person.firstname + "" +person.lastname;
}
FullName (); This sentence has no output, because there is no output value in the FullName function
function FullName2 () {
Return document.write (Person.firstname + person.lastname);//The document.write of this sentence corresponds to System.out.print,
So, returning its value is equivalent to not returning anything.
}
document.getElementById ("Demo"). InnerHTML =fullname2 ();//This sentence is used in conjunction with the FullName function
FullName2 ();//Call Function fullName2
</script>

</body>


Example 4 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

Undefined

John doe



Example 5:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566,
}
function FullName () {
return person.firstname + "" +person.lastname;
}
FullName (); This sentence has no output, because there is no output value in the FullName function
function FullName2 () {
document.write (Person.firstname + person.lastname);//The document.write of this sentence corresponds to System.out.print,
So, only output, no return
}
document.getElementById ("Demo"). InnerHTML =fullname2 ();//This sentence is used in conjunction with the FullName function
FullName2 ();//Call Function fullName2
</script>

</body>


Example 5 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

Undefined

John doe




Example VI:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566
}
function FullName ()
{
document.write (Person.firstname + "" + person.lastname);
}

document.getElementById ("Demo"). InnerHTML =fullname ();//Because the function FullName has no return value, only the output value,
So, call this function, overwrite the demo, for undefined,
And because there are output values, the output of John Doe
</script>

</body>


Example 6 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

Undefined

John Doe

Example 7:
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566
}
function FullName ()
{
document.write (Person.firstname + "" + person.lastname);
return 0;
}

document.getElementById ("Demo"). InnerHTML =fullname ();
</script>

</body>


Example 7 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

0

John Doe



Example 8:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<body>

<p> Create and use object methods. </p>
The <p> object method is stored in the object properties as a function definition. </p>
<p id= "Demo" ></p>
<script>
var person = {
FirstName: "John",
LastName: "Doe",
id:5566
}
function FullName ()
{
document.write (Person.firstname + "" + person.lastname);
return null;
}

document.getElementById ("Demo"). InnerHTML =fullname ();
</script>

</body>


Example 8 results:
Create and use object methods.

Object methods are stored in object properties as a function definition.

John Doe

Look at the results of various forms of functions in script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.