typescripttypescript2.0method-declaration

Typescript Function Declaration, style difference


I started to use Typescript and i don't get what differences in these method declarations are:

onSave(){ /*method body*/ }
public onSave = () => { /*method body*/ }

Also, What I am supposed to search on Google or StackOverflow to find more about this topic?

Thank you,

(Sorry for the long post :D)


Solution

  • You are referring to regular functions and arrow function, they're explained in detail in TypeScript docs: http://www.typescriptlang.org/docs/handbook/functions.html

    The general difference between a regular function and arrow function is that regular function operates within it's own scope (this) while arrow function remains in the scope of the parent.