mirror of
https://github.com/edu4rdshl/gnome-shell.git
synced 2026-07-18 07:34:54 +00:00
util: Add classExtends function
Javascript doesn't have a builtin operator for checking if one class is a subclass of another (ie. instanceof needs an instance, not a class). This commit adds a new function, classExtends, that loops through the class inheritance hierarchy to find if a relationship exists.
This commit is contained in:
parent
b41f2ed98b
commit
c9827cdaa6
1 changed files with 23 additions and 0 deletions
|
|
@ -279,6 +279,29 @@ export function lerp(start, end, progress) {
|
|||
return start + progress * (end - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Function} Class
|
||||
* @description A class
|
||||
*
|
||||
* Note: A class (as defined by the ES6 class keyword)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Class} subClass
|
||||
* @param {Class} superClass
|
||||
* @returns {boolean}
|
||||
*
|
||||
* Returns whether `subClass` is a subclass of `superClass` or not
|
||||
*/
|
||||
export function classExtends(subClass, superClass) {
|
||||
for (let prototype = subClass?.prototype; prototype; prototype = Object.getPrototypeOf(prototype)) {
|
||||
if (prototype === superClass?.prototype)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _GNOMEversionToNumber:
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue