1

What is the difference between greet and greet1 in the below example?

var Greeter = /** @class */ (function () {
    function Greeter(message) {
        this.greet = function () {
            return "Hello, " + this.greeting;
        };
        this.greeting = message;
    }
    Greeter.prototype.greet1 = function () {
        return "Hello, " + this.greeting;
    };
    return Greeter;
}());
Charan
  • 119
  • 1
  • 9
  • 4
    `greet` is an own property of any instance of `Greeter`, and will create a new copy of the function every time the `constructor` is invoked. `greet1` is on the `prototype` of any instance of `Greeter`, and references the same copy of the function for every object. – Patrick Roberts Jun 20 '18 at 05:36

0 Answers0