+ 7

How to pass a Class as a parameter of a function in JS?

Is it possible to pass a class as a argument of function either in pure JS (ES6) or Typescript?

25th Apr 2018, 9:28 PM
Aaron Sarkissian
Aaron Sarkissian - avatar
6 Answers
+ 4
Aaron Sarkissian turns its possible,and ive also found a use,you need functions that accept classes as argument so you can call static methods in them With this sort of function,you can control which classes are being initialised,which classes methods should get called e.t.c https://code.sololearn.com/Weu8l4eC8QwP/?ref=app
25th Apr 2018, 10:11 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 5
🇳🇬Brains Agree. But this was my friends interview questions.. It was interesting for me too that how we should do it, and why? I'll try to find a case where this can be helpful and the way we should do it.
25th Apr 2018, 10:01 PM
Aaron Sarkissian
Aaron Sarkissian - avatar
+ 5
🇳🇬Brains Thanks man. I really appreciate it, good job. 😊
25th Apr 2018, 10:17 PM
Aaron Sarkissian
Aaron Sarkissian - avatar
+ 3
25th Apr 2018, 10:02 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
i doubt its possible,even so i dont think it would be a neccessary feature since i dont think anything might be achievable with that.The general thing is passing an instance of the class(object) as an argument
25th Apr 2018, 9:43 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
You can do it but why?
25th Apr 2018, 10:13 PM
KrOW
KrOW - avatar