I'm actually trying to differentiate (in my code) functions and classes.
I need to know, in a simple console.log, if the parameter of my function is a class or a simple function.
I'm actually taking about class, not object, but really a class.
Like:
function(item){
if(isClass(item)){
console.log('it s a class !');
}else{
if(isFunc(item)){
console.log('it s a function !');
}
}
}
Edit : angular 2 is able to distinguish a function and a class in his injector container class
There aren't any classes in JavaScript. Though functions can be instanciated with the new
keyword.
You can check if something is a function with instanceof
:
var a = function() {};
a instanceof Function; // true
An instanciated function will be an instance of that specific function:
var b = new a();
b instanceof Function; // false
b instanceof a; // true
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