protoobject
Version:
A universal class for creating any JSON objects and simple manipulations with them.
32 lines (31 loc) • 974 B
JavaScript
import { ProtoObject } from "../classes/proto-object.js";
/**
* A factory for creating classes based on the ProtoObject class
*
* @param methods - Methods that should be updated in the class being created.
* @returns - an ProtoObject's heir
*/
export function protoObjectFactory(methods) {
class CProtoObject extends ProtoObject {
constructor(data) {
super(data);
if (methods) {
Object.keys(methods)
.filter((key) => typeof this[key] === "function")
.map((key) => key)
.forEach((key) => {
this[key] = methods[key];
});
}
}
}
if (methods) {
Object.keys(methods)
.filter((key) => typeof CProtoObject[key] === "function")
.map((key) => key)
.forEach((key) => {
CProtoObject[key] = methods[key];
});
}
return CProtoObject;
}