Closed gsklee closed 8 years ago
Variable variables aren't a thing in ES6 at all are they? If not then this couldn't be a simple syntactical transform.
Sent from my iPhone
On 25 May 2015, at 10:06, G. Kay Lee notifications@github.com wrote:
Is dynamically named virtual methods somewhere on the road map? Something like this would be really handy and make it parallel with "real" methods in terms of features:
const assign = function(...s) { return Object.assign(this, ...s); };
const name = 'assign';
console.log( {x:1}::name ); — Reply to this email directly or view it on GitHub.
This is basically eval
which we want to avoid.
You can always use property lookup for dynamic names - limiting ("whitelisting") the available methods to only that available on the object is a desirable side effect.
const methods = {assign}; // and more
// use {__proto__:null, assign} to be safe
let x = {x: 1};
let name = "assign";
x::(methods[name])({y: 2});
console.log(x);
@bergus Good idea, thanks! :+1:
Is dynamically named virtual methods somewhere on the road map? Something like this would be really handy and make it parallel with "real" methods in terms of features: