I came across an interesting article on self-invoking functions in JavaScript by Minko Gechev. This article teaches us how to create a JavaScript function that calls itself immediately after being initialized. I am curious about how we can achieve this in TypeScript. When I attempted to write the code within export class ComponentName
, it did not work.
Here's the code snippet I tried:
import {Component, Input} from '@angular/core'
@Component({...})
export class MyComponent{
@Input() infoes;
(function(){
console.log('testing');
})();
}
The IDE displayed an error stating
unexpected token. a constructor, accessor, method or property was expected
. I believe this error is related to the class concept introduced in TypeScript.