// First we need to create a function constructor
// Function constructors are functions made to create new objects off of arguments you pass down
let Person = function(name, age, profession) {
this.name = name;
this.age = age;
this.profession = profession;
};
// This function creates a new person based on what information you pass down into it
let nox= new Person('Nox', 68, 'Professional Bish');
// I am creating a brand new person called Nox
console.log(nox); // returns { name: 'Nox', age: 68, profession: 'Professional Bish' }
// The prototype is a property with an object as a value that comes with every object in JavaScript
// In order to access it all you need to do is:
Person.prototype
// In order to write to it you just create a method under that object
Person.prototype.greet = function() {
console.log(`Hi there! My name is ${this.name} and I am a ${this.profession}`)
}
nox.greet(); // Returns 'Hi there! My name is Nox and I am Professional bish'
// You can access the object using the this keyword within the protoype
// Be careful not to use ES6 arrow functions here because the open up the lexical scope and change what the this keyword is referring to