-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual properties (accessors) as well as virtual methods #33
Comments
WRT Chai's |
Yeah, I thought that would be one of the first things mentioned 😉 The same could be said of my first example, that |
It's the most interesting part of abstract references which we lost after withdrawing this proposal. https://github.com/zenparsing/es-abstract-refs |
That wouldn't work, because of ambiguity being impossible to resolve. Say we have this: const fn = { a: () => 1 };
const prop = createAccessor({
get: function () { return ({ a: () => 2 }); }
});
x::fn.a() // 1
// desugars to
fn.a.call(x);
// on the other hand,
// if we desugared this
x::prop
// to
prop.get.call(x)
// then would this
x::prop.a()
// be desugared to
prop.get.call(x).a() // ? is that what you wanted?
// however, if align with prev example, we'll get this
prop.a.call(x) |
Note that we can get close with a proxy:
var obj = {};
obj::data.x = 15;
obj.x; // undefined
obj::data.x; // 15 |
I was pointing that it would be impossible to disambiguate: obj::data.fn(); whether it is a binded property accessor |
or more clear, with precedence in place:
And note, latter is highly undesirable. |
FWIW agreed '::' should have lower priority than '.' or it would lose most Needing a reference upfront or parenthesis to explicit make it lower On Friday, 15 July 2016, Igor Oleinikov [email protected] wrote:
|
This sounds like something better suited to suggest in the private fields repo. I don't think any suggestion here would gain much traction. |
I'm a huge fan of this proposal, I'd really like to see it advance to Stage 1 and beyond. I'd also like to get some thoughts on providing virtual accessors as well as virtual methods. For example, lets assume some kind of
Reflect.createLooseAccessor()
function:This reminds me of jQuery's
data()
, but doesn't change the target object, making it possible to use it on immutable objects. Another real-world example:Chai's
should
sits onObject.prototype
is generally a bad idea if the value being tested is potentially undefined or has no [[Prototype]] (e.g. an object created withObject.create(null)
). As a virtual accessor, it doesn't infect anything and can be used on any value type.I realise there are significant conflicts with the current proposal (such as
foo::data
behaving differently for a virtual accessor), but my goal is just to spark a discussion about it. I also realise that esdiscuss might be a better place to raise this, but thought it a good idea to get some feedback from proponents of this proposal first.The text was updated successfully, but these errors were encountered: