problems(js): add “2618. Check if Object Instance of Class”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
8a7ffff7d2
commit
86599c22a7
1 changed files with 16 additions and 0 deletions
16
problems/js/check-if-object-instance-of-class.js
Normal file
16
problems/js/check-if-object-instance-of-class.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* @param {any} obj
|
||||
* @param {any} classFunction
|
||||
* @return {boolean}
|
||||
*/
|
||||
var checkIfInstanceOf = function(obj, classFunction) {
|
||||
if (obj === null || obj === undefined || typeof classFunction !== "function") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Object(obj) instanceof classFunction;
|
||||
};
|
||||
|
||||
/**
|
||||
* checkIfInstanceOf(new Date(), Date); // true
|
||||
*/
|
Loading…
Reference in a new issue