(abstract) new Element()
Abstract base class for all circuit elements in the JSCircuit Editor.
- Description:
Abstract base class for all circuit elements in the JSCircuit Editor.
This class serves as the foundation for all physical circuit components (resistors, capacitors, wires, etc.) and defines the common interface that all elements must implement.
🔧 Extension Point for Developers: To create a new circuit element type, extend this class and implement the required properties and methods. See the examples below for implementation patterns.
Key Properties:
id: Unique identifier for the elementnodes: Array of Position objects defining connection pointslabel: Optional text label for displaytype: Element type identifier (set by subclasses)properties: Container for element-specific properties
- Source:
Examples
// Creating a new element type
class CustomElement extends Element {
constructor(id, nodes, label, properties) {
super(id, nodes, label, properties);
this.type = 'custom';
}
describe() {
return `Custom element ${this.id}`;
}
}
// Using an existing element
const resistor = new Resistor(
'R1',
[new Position(0, 0), new Position(50, 0)],
new Label('1kΩ'),
new Properties({ resistance: 1000 })
);