The use and non-use of the word Function in Typescript

Asked

Viewed 47 times

2

Why when I declare method in a class the compiler beeps, stating that the word usage is wrong function.

In previous lessons of my learning to create a function I signed first as function.

abstract class Empregado {    
    abstract getFuncao():string;
}

class Professor extends Empregado {
    getFuncao():string {
        return "Professor";
    }
}

class Diretor extends Empregado {
    getFuncao():string {
        return "Diretor";
    }
}

1 answer

1


The answer is already in the question.

Because you do not declare functions within a class, declare methods, then it would make no sense to use function. In addition to what within a class the compiler has more control over what is happening (the syntax is less ambiguous) and can determine the beginning and end of the method, for example it cannot have one method within another, but it is possible to have a function within a method.

  • Interesting! As you mentioned, I answered, but it was a curiosity, IE, Function is more for scripts procedural level.

  • 1

    @Macario1983

Browser other questions tagged

You are not signed in. Login or sign up in order to post.