Skip to content

Instantly share code, notes, and snippets.

@scheakur
Created February 8, 2015 07:29
Show Gist options
  • Save scheakur/437a67464517abc0b4c0 to your computer and use it in GitHub Desktop.
Save scheakur/437a67464517abc0b4c0 to your computer and use it in GitHub Desktop.
like-ruby-new.js
#! 6to5-node
'use strict';
class Struct {
static new(...props) {
return class {
static new(...args) {
return new this(...args);
}
constructor(...args) {
props.forEach((property, index) => {
this[property] = args[index];
}, this);
}
};
}
}
class Greeting extends Struct.new('to', 'message') {
hey() {
console.log(`Hey, ${this.to}! ${this.message}`);
}
}
Greeting.new('you', 'Shut up and write code!!').hey(); // => Hey, you! Shut up and write code!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment