How can I mimic this JavaScript inheritance in ClojureScript?
class AccessController extends EventEmitter {
static async create (db, options) { }
static get type () {
throw new Error('\'static get type ()\' needs to be defined in the inheriting class')
}
get type () {
return this.constructor.type
}
async canAppend (entry, identityProvider) {
return true
}
}
class OtherController extends AccessController {
constructor (db, options) {
super()
}
static async create (db, options) {
return new OtherController (db, options)
}
static get type () {
return 'othertype'
}
async canAppend(entry, identityProvider) {
return true
}
}
Mu understanding is that:
static
is a property of the object itself-.prototype
This would be achieved like that:
(defn- OtherController
{:jsdoc ["@constructor"]}
[orbitdb options]
(this-as this
(.call AccessController this orbitdb options)
this))
(defn create-access-controller []
(gobj/extend
;; inheritance
(.-prototype OtherController)
(.-prototype AccessController)
;; methods
#js {:canAppend (fn [entry identity-provider]
true)})
;; static properties
(set! (.. OtherController -type) "othertype")
(set! (.. OtherController -create) (fn [db options]
(new OtherController db (clj->js {}))))
OtherController)
I'm not sure how to:
get
sugar,AccessController extends EventEmitter
how can I inherit the static
properties of EventEmitter
, if any?get
you can create via Object.defineProperty.static
properties aren't usually inherited I think but you can probably just do the same gobj/extend
call for the classes themselves, not their prototype.