Object-Oriented JavaScript

Inheritance

Object Oriented JS

Object-Oriented Basics

Object Creation

 

  • Public Methods
  • Private Methods
  • Privileged Methods

Prototypal Inheritance

Creating Reusable Code

Person Class

// Create the constructor for a //Person object
function Person( name ) {
this.name = name;
}
// Add a new method to the Person //object
Person.prototype.getName = function() {
return this.name;
};

User Class

// Create a new User object constructor
function User( name, password ) {
this.name = name;
this.password = password;
};
// The User object inherits all of the Person object's //methods
User.prototype = new Person();
// We add a method of our own to the User object
User.prototype.getPassword = function() {
return this.password;
};

Object-Oriented JavaScript

By Anuj Upadhyay

Object-Oriented JavaScript

  • 313