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