mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-07-20 16:37:08 +00:00
Move initialization logic for sub-classes to Class
constructor (#8872)
This commit is contained in:
@ -13,21 +13,7 @@ export class Class {
|
||||
// [Extends the current class](#class-inheritance) given the properties to be included.
|
||||
// Returns a Javascript function that is a class constructor (to be called with `new`).
|
||||
static extend({statics, includes, ...props}) {
|
||||
const NewClass = function (...args) {
|
||||
|
||||
Util.setOptions(this);
|
||||
|
||||
// call the constructor
|
||||
if (this.initialize) {
|
||||
this.initialize.apply(this, args);
|
||||
}
|
||||
|
||||
// call all constructor hooks
|
||||
this.callInitHooks();
|
||||
};
|
||||
|
||||
// inherit parent's prototype
|
||||
Object.setPrototypeOf(NewClass.prototype, this.prototype);
|
||||
const NewClass = class extends this {};
|
||||
|
||||
// inherit parent's static properties
|
||||
Object.setPrototypeOf(NewClass, this);
|
||||
@ -90,6 +76,20 @@ export class Class {
|
||||
return this;
|
||||
}
|
||||
|
||||
_initHooksCalled = false;
|
||||
|
||||
constructor(...args) {
|
||||
Util.setOptions(this);
|
||||
|
||||
// call the constructor
|
||||
if (this.initialize) {
|
||||
this.initialize(...args);
|
||||
}
|
||||
|
||||
// call all constructor hooks
|
||||
this.callInitHooks();
|
||||
}
|
||||
|
||||
callInitHooks() {
|
||||
if (this._initHooksCalled) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user