class – typescript to js

ref – https://www.geeksforgeeks.org/typescript-class/

typescript

gets converted to js:

What does ‘this’ reference inside a function in an IIFE?

We have functions in IIFE, and we see that it uses this. But what does this reference?
As you can see from the example below, the ‘this’ keyword refers to the IIFE object.

> test4.bye()

“bye bye”

> test4.hello()

hello reference sayHello function. sayHello logs the ‘this’ keyword of the IIFE.
It will display the IIFE object.


Object
bye: ƒ sayBye()
hello: ƒ sayHello()
__proto__: Object
“hallo!!!ricky”

However, notice that we return a literal object. We can’t use new on the literal object because it’s not a function. So we must change this a bit in order to accomodate ‘new’.

So in our IIFE Student, we have a function constructor Student. That way when we go new Student, it would be valid because we can instantiate a function instructor.

Accessing Attributes and Functions

A class’s attributes and functions can be accessed by the object. With the help of ‘ . ’ dot notation or bracket notation([”]) we access the data members of a class.