Options
All
  • Public
  • Public/Protected
  • All
Menu

An object that can be used to emulate classes and a class hierarchy in JavaScript. This works even for old browsers that do no support the native class syntax yet. Note however, that this should be mostly compatible with the new class syntax of JavaScript, so consider creating your own widgets as a class:

class MyWidget extends PrimeFaces.widget.BaseWidget {
init(cfg){
// ...
}
}

Note for TypeScript users: Normally you should just write a widget as a class that extends from the appropriate base class. If you must use this method you will need to specify the type parameters explicitly. The best way to do so is by defining the interfaces for the classes separately:

interface BaseWidgetCfg {
prop1: string;
}
interface AccordionCfg extends BaseWidgetCfg {
prop2: boolean;
}
interface BaseWidget {
init(cfg: BaseWidgetCfg): void;
method1(x: number): boolean;
}
interface Accordion extends BaseWidget {
init(cfg: AccordionCfg): void;
method1(): boolean;
method2(): boolean;
}

Now you can use it normally:

const BaseWidget = Class.extend<BaseWidget, [BaseWidgetCfg]>({
init(cfg: BaseWidgetCfg) {
// ...
},
method1(x: number): boolean {
return x > 0;
},
});
const Accordion = BaseWidget.extend<Accordion, [AccordionCfg]>({
init(cfg: AccordionCfg) {
this._super(cfg);
},
method1() {
return !this._super(42);
},
method2() {
return true;
}
});
const base: BaseWidget = new BaseWidget({prop1: ""});
const accordion: Accordion = new Accordion({prop1: "", prop2: true});
base.method1(2);
accordion.method1();
accordion.method2();

Type Parameters

  • TBase = Record<string, unknown>

Hierarchy

  • Class

Index

Constructors

Methods

Constructors

Methods

  • Type Parameters

    • TSub extends { init: any } & Omit<TBase, "init">

    • TArgs extends never[]

    Parameters

    Returns PrimeFaces.Class<TSub> & (new (...args: TArgs) => TSub) & { prototype: TSub }

Generated using TypeDoc