JAVASCRIPT OBJECT METHODS

Norman Reedus

Total Post:45

Points:315
Posted by  Norman Reedus
 467  View(s)
Ratings:
Rate this:
We want to use JavaScript Object Methods. How to use this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: JavaScript Object Methods

    <!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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!