There is another difference, in that the readonly
modifier cannot be applied to methods. Therefore, the following assignment cannot be prevented:
interface Foo {
bar(): void;
}
declare var x: Foo;
x.bar = function () { };
If bar
is defined as a property, then the readonly
modifier can be applied to it:
interface Foo {
readonly bar: () => void;
}
preventing reassignment.