Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
In JavaScript you can define functions as object methods. The following example creates an object (Person), with two properties (firstName and lastName), and a method (fullName):
function Person(firstName, lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
this.FullName = function () { return this.FirstName + " " + this.LastName; }
}
let demo1 = document.getElementById("demo1");
let person1 = new Person("Ricky", "Bobby");
demo1.innerHTML = person1.FullName();