What practical differences are there between defining an interface method:
interface Foo { bar(): void; }
and defining a property with a function type:
interface Foo { bar: () => void; }
?
In most cases, methods are actions and properties are qualities. Using a method causes something to happen to an object, while using a property returns information about the object or causes a quality about the object to change.
A function is a set of instructions or procedures to perform a specific task, and a method is a set of instructions that are associated with an object.
The difference between b/w property and method is that - property is a value stored in the hash key, whereas method is a function stored in the hash key.
As I understand it, property is calculated when an object is created. And method makes calculations when I call it.
If these are the only declarations, these are identical.
The only difference is that you can augment the first form in a second declaration to add new signatures:
// Somewhere interface Foo { bar(): void; } // Somewhere else interface Foo { bar(s: number): void; } // Elsewhere let x: Foo = ... x.bar(32); // OK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With