Author: Zeta Ret
Object prototypes for OOP
Version: 1.7.0
Date: 2017 - Today
required*
All ProtoSS functionality, instance is generated immediately
ZetaRet_Prototypes() : void
return void
rndstr(Number l) : String
- l* - Number, generates random string with length of characters
return String, random string
super(function_arguments|Array args, Array|Boolean cargs, String name) : Object
- args* - function_arguments|Array, function arguments object if supported, or manually created Array [] with assigned 'callee' reference to the function class object
- cargs* - Array|Boolean, Array used to call 'apply' of the super constructor function, Boolean true will use arguments as call arguments (cargs=args)
- name - String, String used to define the name of the constructor in the prototype, default __constructor
return Object, constructor function result
superize(function_arguments|Array args, Object map, Boolean setname, Boolean setown, Boolean defname) : Object
- args* - function_arguments|Array, function arguments object if supported, or manually created Array [] with assigned 'callee' reference to the function class object
- map - Object, if null will use 'this' object to enumerate all assigned functions, used for member methods, functions in map will be assigned to 'this'
- setname - Boolean, changes name of iterated function according to key, function.aname
- setown - Boolean, adds constructor name to function name, requires setname, i.e. 'myfunction#myclass', function.oname
- defname - Boolean, adds setname and setown to function.name property
return Object, with all functions assigned to this function class in particular
setSuper(Function superfn, Function fn, String name) : Function
- superfn* - Function, the super function of fn or this
- fn - Function, if null will use this function, fn extends superfn in effect, fn is subclass of superfn
- name - String, if null will use default __constructor
return Function, superfn will be returned for chain calls
setSubclass(Function fn, Function superfn, String name) : Function
- fn* - Function, fn extends superfn in effect, fn is subclass of superfn
- superfn - Function, if null will use this function, the super function of fn
- name - String, if null will use default __constructor
return Function, superfn will be returned for chain calls
callSuper(String name, Array args, String cname) : Object
- name* - String, name of super function
- args - Array, array of arguments to apply
- cname - String, constructor name, if null will use __constructor
return Object, result of next super function different than this[name] function
callSuper2(String name, Array args, String cname) : Object
- name* - String, name of super function
- args - Array, array of arguments to apply
- cname - String, constructor name, if null will use __constructor
return Object, result of super function, may call the same function object as this[name] function
callSuperX(String name, Array args, String cname, Function thiscls) : Object
- name* - String, name of super function
- args - Array, array of arguments to apply
- cname - String, constructor name, if null will use __constructor
- thiscls - Function, accepts current constructor class scope for continues upwards super calls, uses getNextSuperX, works with super constructor lists, compatible with XeltoSS (ProtoSS JS Class)
return Object, result of next super function different than thiscls.prototype.map[name] function or this.map[name] function
getNextSuper(String name, String cname) : Function
- name* - String, search super function by name in super map created by superize
- cname - String, constructor name, if null will use __constructor
return Function, next function in super maps after calling getSupers()
getNextSuperX(String name, String cname, Function thiscls) : Function
- name* - String, search super function by name in super map created by superize
- cname - String, constructor name, if null will use __constructor
- thiscls - Function, accepts current constructor class scope for interpolating next super properly, detects prototype method maps, compatible with XeltoSS (ProtoSS JS Class)
return Function, next function in super maps after calling getSupers() on thiscls or this
getSuper() : Object
return Object, super object map of next super class as it was created by superize
getThis() : Object
return Object, super object map of this object as it was created by superize
callProto(Function proto, String name, Array args) : Object
- proto* - Function, prototype constructor function of any of the supers, it will use super object map by proto.name
- name* - String, name of the function to call on the super object map
- args - Array, array of arguments to apply
return Object, result of the super prototype function as it is defined in its function scope
callProto2(Object proto, String name, Array args) : Object
- proto* - Object, super object map obtained from the same object, may simulate by using an Object with assigned 'constructor' from the supers
- name* - String, name of the function to call on the super object map
- args - Array, array of arguments to apply
return Object, result of the super prototype function as it is defined in its function scope
callProtoX(Object proto, String name, Array args) : Object
- proto* - Object, prototype constructor function of any of the supers, it will use super object map by proto.name or prototype of the function
- name* - String, name of the function to call on the super object map or prototype of the function
- args - Array, array of arguments to apply
return Object, result of the super prototype function as it is defined in its function scope, support of XeltoSS (ProtoSS JS Class) prototype chain
superList(Array list, Function fn, String name, Boolean defname) : Function
- list* - Array, list of constructor functions used as supers
- fn - Function, if null will use this, fn extends aggregate function which calls the list with constructors, the aggregate function uses __constructor_list instead of __constructor
- name - String, name of constructor, if null will use __constructor
- defname - Boolean, adds function.name property, aname is always added now
return Function, fn for chain calls
superList2(Array list, Function fn, String name, Boolean defname) : Function
- list* - Array, list of constructor functions used as supers
- fn - Function, if null will use this, fn extends aggregate function which calls the list with constructors (uses same arguments for all supers, superList requires an array of arguments, each index exactly matching the super index), the aggregate function uses __constructor_list instead of __constructor
- name - String, name of constructor, if null will use __constructor
- defname - Boolean, adds function.name property, aname is always added now
return Function, fn for chain calls
getSupers(Function fn, String name) : Array
- fn - Function, if null will use this
- name - String, if null will use __constructor
return Array, all super constructor functions, allows caching inside function object
getSupers2(Function fn, String name) : Array
- fn - Function, if null will use this
- name - String, if null will use __constructor
return Array, super constructor function or functions (if super is aggregate will use __constructor_list
getReversedSupers(Function fn, String name) : Array
- fn - Function, if null will use this
- name - String, if null will use __constructor
return Array, all super constructor functions, reversed order
hasSuper(Function sfn, Function fn, String name) : Boolean
- sfn* - Function, super function to check against
- fn - Function, if null will use this, to obtain all supers
- name - String, if null will use __constructor
return Boolean, true - if it exists in the inheritance tree, otherwise false
is(Function sfn, Function fn, String name) : Boolean
- sfn* - Function, super function to check against
- fn - Function, if null will use this, to obtain all supers
- name - String, if null will use __constructor
return Boolean, true - if it exists in the inheritance tree or equals this constructor, otherwise false
abstract(String name, Object amap, Boolean defname) : Function
- name - String, if null will use ZetaRet_Abstract_XXX13XXX
- amap - Object, if null will use this, i.e. {term:0,date:0,record:3}.abstract()
- defname - Boolean, adds function.name property, aname is always added now
return Function, afn is aggregate function which generates methods according to map (uses statis), if key-value pair is [0,false,null,undefined,''] will throw abstract error, otherwise will return the value from the object map (i.e. .record() returns 3), abstract class throws error on instance, must be subclassed
implement(Function superfn, Function fn, String name) : Function
- superfn* - Function, the super function of fn or this
- fn - Function, if null will use this function, fn extends superfn in effect, fn is subclass of superfn
- name - String, if null will use default __constructor
return Function, superfn will be returned for chain calls, [implement calls setSuper]
interface(String name, Object imap, Boolean defname) : Function
- name - String, if null will use ZetaRet_Interface_XXX13XXX
- imap - Object, if null will use this, i.e. {term:[String, Number],date:[Date],record:[CustomRecordClass, IRecordData]}.interface()
- defname - Boolean, adds function.name property, aname is always added now
return Function, ifn is aggregate function which generates methods according to map (uses statis), methods will test arguments against map value input types, each method returns true or false, depending on matched types
final(function_arguments|Array args) : Object
- args* - function_arguments|Array, compares this.constructor and args.callee, will throw error if not equal, a class with final call must not be a super
return Object, this
_statis(function_arguments|Array args, Function statis, Object super, Boolean setname, Boolean setown, Boolean defname) : Object
- args* - function_arguments|Array, function arguments object if supported, or manually created Array [] with assigned 'callee' reference to the function class object
- statis - Function, static function assign to object, these functions act like prototype functions and as such are not generated per new instance (superize), statis(Object s, Function constructor){s.myf=function(){};}
- _super - Object, if null will use callee[prfx+callee.name+sffx] object to enumerate all assigned functions, used for member methods, functions in map will be assigned to 'this'
- setname - Boolean, changes name of iterated function according to key, function.aname
- setown - Boolean, adds constructor name to function name, requires setname, i.e. 'myfunction#myclass', function.oname
- defname - Boolean, adds setname and setown to function.name property
return Object, all functions assigned to this function class
getSuperName() : String
return String, package+::+name, works only on instances using constructor static properties
getSuperName2() : String
return String, package+::+name, works on instances and classes using constructor static properties
namespace(String ns, Function cls, Object pack) : Object
- ns* - String, id of namespace, will create new package in effect with prefix
- cls* - Function, function to import into package, uses internal call
- pack - Object, if null uses this
return Object, package object defining new namespace
usens(String ns, Object pack) : Object
- ns* - String, id of namespace
- pack - Object, if null uses this
return Object, resolved package object using namespace prefix
internal(Function cls, Object pack) : Object
- cls* - Function, class function, must provide name
- pack - Object, if null uses this
return Object, last package object
package(String name, Object scope) : Object
- name* - String, name of package, use .(dot) for delimiter
- scope - Object, if null uses this, scope for attaching/reading package, use window in most of the time or globally accessible object
return Object, last package object