Last active
August 29, 2015 14:15
-
-
Save scheakur/4adef1705b4aa23db9d4 to your computer and use it in GitHub Desktop.
like-ruby-struct-new.js
This file contains 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
#! 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