Add New Method


A Javascript Object method is a property that contain a function defination.

Code Structure
function person(firstName, lastName, age) {
 this.firstName = firstName;
 this.lastName = lastName;
 this.age = age;
 this.changeLastName = function (lastname) {
  this.lastName = lastname;
 }
}
var myfriend = new person("Bill", "Gaates", 25);
myfriend.changeLastName("Gates");
alert("His last name is " + myfriend.lastName);

Share this

Related Posts