Not sure if I'm missing something, but wouldn't it be trivial to code that 
constructor in JS?

class Result {
  constructor (type, value=true) {
    this[type] = value;
function add(data) {
  if (data !== Object(data)) {
    return new Result('error', new Error('The data is not an object.'));
  return new Result('success');
console.log(add({}).success); // true
console.log(add(12).error.message); // 'The data is not an object.'

es-discuss mailing list

Reply via email to