On Oct 17, 2011, at 5:18 PM, David Herman wrote: > I suspect it's not nearly so rare as you think. For example, it just showed > up in Tom and Mark's new proxy proposal: > >> The protect trap is called on >> Object.{freeze,seal,preventExtensions}(aProxy). The operation argument is a >> string identifying the corresponding operation (“freeze”, “seal”, >> “preventExtensions”). This makes it easy for a handler to forward this >> operation, by e.g. performing Object[operation](obj). > > > A simple way to abstract out "do this concrete operation" to "do one of the > following set of possible concrete operations" is to pass the name as a > string. Yes, there's a certain aesthetic that says that's icky, but JS makes > it so convenient that it's the obvious thing to do.
JS libraries are full of computed method name calls. It's quite common. http://codesearch.google.com/#search/&q=%22%5D(%22%20lang:js&type=cs /be > > Dave > > On Oct 17, 2011, at 4:15 PM, Allen Wirfs-Brock wrote: > >> >> On Oct 17, 2011, at 3:34 PM, David Herman wrote: >>> >>> >>>> IMHO the single "property name space" of es-current is a feature, not a >>>> bug. >>> >>> I tend to agree. There are expressibility problems, too. For example, if >>> you have an object that uses . for its API and [] for some other data, then >>> what do you do when you want to dynamically compute an API name? >> >> In most languages, this would fall into the realm of the reflection API. >> >> What is the actual frequency of such driven API member selection. If it is >> high (particularly, high than the utility of good collections) that we may >> be exposing other problems we need to look at more closely. >> >> >>> I would hope not >>> >>> eval("obj." + computeName()) >>> >>> But I don't see any obvious ways out of this that aren't pretty convoluted. >>> >> >> I'll give you four: >> >> 1) Object.getOwnPropertyDescriptor(obj,name).value >> etc. >> >> 2) two new reflection functions: >> Object.getProperty(obj,name) >> Object.setProperty(obj,name,value) >> >> 3) build upon the possible alternative private name property syntax >> let foo='foo'; >> obj@foo >> or perhaps >> obj@('foo') >> >> 4) a switch statement: >> switch (computedAPIName) { >> case 'property1': >> obj.property1(/*args */); >> break; >> case 'property2': >> obj.property2(/*args */); >> break; >> case 'property3': >> // etc. >> } >> >> All of these start from the perspective that this sort of reflective API >> access should be quite rare. >> >> Allen >> >> >> >> >> > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss