Tip 39: Extend Existing Prototypes with Class
Up to this point, you’ve created object instances from classes, but not from
new object instance using the
new keyword, you’d use a function. You’ll notice that constructor functions are very similar to a
constructor method on a class. That should be a clue that new syntax will fit in nicely with legacy code.
simply write a function as normal. By convention, when you intend to use a function as a constructor, you’d start the function with a capital letter. Inside the function, you can attach properties to an instance using the
When you create a new instance using the
new keyword, you run the function
as a constructor and bind the
Coupon written as a constructor function.