Created
February 8, 2015 07:29
-
-
Save scheakur/437a67464517abc0b4c0 to your computer and use it in GitHub Desktop.
like-ruby-new.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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