FutuToad
FutuToad

Reputation: 2850

Declare a function in a class

How do you declare a function in a class like so

FooVariable = function FooFunction(FooMethod) {
}

I'm trying to do it this way instead of FooFunction(FooMethod) so that FooFunction doesn't end up in the prototype..

Upvotes: 0

Views: 213

Answers (1)

Fenton
Fenton

Reputation: 250872

If you don't want an instance method like this:

class Foo {
    fooFunction() {

    }
}

You can add the static keyword:

class Foo {
    static fooFunction() {

    }
}

The resulting JavaScript is:

var Foo = (function () {
    function Foo() { }
    Foo.fooFunction = function fooFunction() {
    };
    return Foo;
})();

Upvotes: 2

Related Questions