Skip to content

Instantly share code, notes, and snippets.

@scheakur
Last active August 29, 2015 14:15
Show Gist options
  • Save scheakur/4adef1705b4aa23db9d4 to your computer and use it in GitHub Desktop.
Save scheakur/4adef1705b4aa23db9d4 to your computer and use it in GitHub Desktop.
like-ruby-struct-new.js
#! iojs --harmony
'use strict';
class Struct {
static new() {
var props = Array.prototype.slice.call(arguments);
return class {
constructor() {
var args = Array.prototype.slice.call(arguments);
props.forEach(function(property, index) {
this[property] = args[index];
}, this);
}
};
}
}
class Greeting extends Struct.new('to', 'message') {
hey() {
console.log(`Hey, ${this.to}! ${this.message}`);
}
}
new Greeting('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