mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-08-16 03:34:48 +02:00
move implements and instanceOf methods to inheritance
This commit is contained in:
@ -214,4 +214,38 @@ export class ClassWithAttributes
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The implements function can be used to check whether the object
|
||||
* implements the given interface.
|
||||
*
|
||||
* As TypeScript can not (yet) check if an objects implements an interface on runtime,
|
||||
* we currently implements with each interface a function called 'implements_'+interfacename
|
||||
* to be able to check here.
|
||||
*
|
||||
* @param _iface name of interface to check
|
||||
*/
|
||||
implements (_iface_name : string)
|
||||
{
|
||||
if (typeof window['implements_'+_iface_name] === 'function' &&
|
||||
window['implements_'+_iface_name](this))
|
||||
{
|
||||
return true
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if object is an instance of a class or implements an interface (specified by the interfaces name)
|
||||
*
|
||||
* @param _class_or_interfacename class(-name) or string with name of interface
|
||||
*/
|
||||
instanceOf(_class_or_interfacename: any) : boolean
|
||||
{
|
||||
if (typeof _class_or_interfacename === 'string')
|
||||
{
|
||||
return this.implements(_class_or_interfacename);
|
||||
}
|
||||
return this instanceof _class_or_interfacename;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user