Skip to content

Instantly share code, notes, and snippets.

@zerobias
Last active December 12, 2016 10:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobias/01eae0e49e5542ed85cb8074423fe757 to your computer and use it in GitHub Desktop.
Save zerobias/01eae0e49e5542ed85cb8074423fe757 to your computer and use it in GitHub Desktop.
Native dynamic es6 class mixin
const Storage = Sup => class extends Sup {
save(database) { }
}
const Validation = Sup => class extends Sup {
validate(schema) { }
}
class Person { }
class Employee extends Storage(Validation(Person)) { }
const tap = require('tap').test
const Execution = Sup => class extends Sup { get run() { return true } }
class TestObject { get isTestObject() { return true } }
tap('execution mixin test',
function(t){
class ExtendedObject extends Execution( TestObject ) { }
const tested = new ExtendedObject()
t.ok(tested)
t.ok(tested.isTestObject)
t.ok(tested.run)
t.end()
}
)
/*
# Subtest: execution mixin test
ok 1 - expect truthy value
ok 2 - expect truthy value
ok 3 - expect truthy value
1..3
ok 1 - execution mixin test
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment