Utilities that operate on classes

Usage no npm install needed!

<script type="module">
  import okibaClassUtils from 'https://cdn.skypack.dev/@okiba/class-utils';


Okiba / class-utils

Utilities that operate on classes



npm i --save @okiba/class-utils

Or import it directly in the browser

<script type="module" src="https://unpkg.com/@okiba/class-utils/index.js"></script>


import class-utils from '@okiba/class-utils'

Untranspiled code 🛑

Okiba Core packages are not transpiled, so don't forget to transpile them with your favourite bundler. For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:

  test: /\.js$/,
  exclude: /node_modules\/(?!(@okiba)\/).*/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']

mixin(BaseClass, context, Arguments)

Mixes properties and methods from a class into a given this context

class Fruit {
  constructor() {
    this.isPeeled = false

  peel() {
    this.isPeeled = true

class Coloured {
  constructor(color) {
    this.color = color

class Edible {
  constructor(color) {
    mixin(Fruit, this)
    mixin(Coloured, this, color)

const edible = new Edible('red')
console.log(edible.isPeeled, edible.color)
// Logs: true, 'red'


+ BaseClass: Class

The class definition to mix-in

+ context: Object

The context that has to include methods and props

+ Arguments: any

to pass to the BaseClass constructor