A
A
agentx0012013-08-01 09:28:40
JavaScript
agentx001, 2013-08-01 09:28:40

Misunderstood class declaration?

Good morning, habralyudi!
I came across this code:

var Greeter = (function () {
    function Greeter(message) {
        this.greeting = message;
    }
    Greeter.prototype.greet = function () {
        return "Hello, " + this.greeting;
    };
    return Greeter;
})();

This seems to be a class declaration, but why is it better / worse than the “traditional” implementation?
var Greeter =  function(message) {
   this.greeting = message;
 }
 Greeter.prototype.greet = function () {
     return "Hello, " + this.greeting;
 };

PS: This code generates TypeScript

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Vasilchuk, 2013-08-01
@agentx001

It's just that the class declaration is framed by a closure so as not to "hook" anything from the outside.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question