Home > DeveloperSection > Forums > JavaScript Object Methods
Norman Reedus
Norman Reedus

Total Post:45

Points:315
Posted on    March-28-2016 11:09 PM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 183  View(s)
Rate this:
We want to use JavaScript Object Methods. How to use this please help me.


aditya kumar Patel

Total Post:244

Points:1736
Posted on    March-28-2016 11:10 PM

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>The JavaScript Object Methods</title>

</head>

<body>

<p id="Name"></p>

<script>

function person(firstName, lastName, age, eyeColor) {

this.firstName = firstName;

this.lastName = lastName;

this.age = age;

this.eyeColor = eyeColor;

this.changeLastName = function (name) {

this.lastName = name;

}

this.changeFirstName = function (name) {

this.firstName = name;

}

}

var myfriend = new person("Sally", "Rally", 48, "green");

myfriend.changeFirstName('Ashok');

myfriend.changeLastName('Patel');

document.getElementById("Name").innerHTML= ("My friend name is " + myfriend.firstName + myfriend.lastName);

</script>

</body>

</html>


Don't want to miss updates? Please click the below button!

Follow MindStick