-
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
::new collision? #29
Comments
Thanks for bringing this up; I was hoping we could get some discussion going! Remember that the binary form never looks up properties on the RHS: obj::blahblah; // Bind 'obj' to function 'blahblah' In the above, we don't look up the "blahblah" property of "obj". The best way to think of obj::function(...args) { return new this(...args) } (Currently, it's not implemented quite that way, but it's close enough.) So the RHS can define a "new" property and there's no conflict. class C {
constructor(a) {
this.a = a;
}
static new {
return "Hello";
}
}
console.log(C.new(1)); // "Hello"
console.log(C::new(1)); // { a: 1 } |
idk this is very confusing to me since |
Also, does this mean to bind |
Yes, I think this |
Agreed with Domenic, I personally wouldn't create a precedent where a We passed that phase on ES5 already, allowing Just my 2 cents On Mon, Dec 14, 2015 at 5:11 PM, Domenic Denicola [email protected]
|
Uh, I was shortly confused by this now, but actually it sorts out quite simple. Methods that are named ::Foo.new while only the binary form is attaching a special behavior to the Foo::x // x.bind(Foo)
Foo::new // new.bind(Foo) - invalid anyway, therefore we desugar that to
// (...args) => new Foo(...args) |
For me @bergus, exactly! |
Maybe we should flip the operands and use
instead. Imo this is better because the function that is evenutally going to be called is always on the right side. And there's less confusion, nobody can mistake this as a property access on The only disadvantage could be that it makes the grammar a bit more complicated, as we must prevent this from parsing as |
you are both expecting a special meaning for a name ... try for a second to think
|
However, I agree that this is completely different proposal. Can we reuse otherwise invalid form of the current proposal - that is the question. |
@bergus Right, While technically possible, I don't think it makes sense. You're not binding something to the constructor. You're binding the constructor to a "generic newer method", i.e. function genericNewer(...args) {
return new this(...args);
}
const fooNewer = genericNewer.bind(Foo); Instead of that, we can simple write: const fooNewer = Foo::new; @WebReflection Yes, |
@zenparsing but |
@bmeck Keywords are re-used in various places, e.g. The benefit of |
@zenparsing meta-properties are very explicit (the fact that new cannot be an identifier), while I don't feel that this syntax is clear since it is on the right hand side of an operator with similar feeling to the |
also if |
@bmeck I can tell that you don't like it, but why exactly? Is it because that you feel it confuses property lookup with binding? If so, then why do you think that's not a problem for the entire proposal? In other words, why is: Foo::new; A problem for you, but, import { something } from "somewhere";
foo::something(); not? |
@zenparsing
It also is confusing since |
Having a syntax with an operator that mimics a binary operator : |
@bmeck But the point is that "something" could equally be confused with property lookup as
Again, the same exact argument could be applied to True, this is a special-case overload of the |
@WebReflection, you are right.... it is true. Now I'm started to think that this proposal can be abandoned in favor of plain ES6 helper function function NEW(...args) {
return new this(...args)
} Or the hypothetical TypeScript (with variadic generics or variadic kinds, and thisArg typing) function NEW<T, ...Args>{new:(...args:...Args):T}::(...args: ...Args): T {
return new this(...args);
} Thus, Um? |
@Artazor Yeah, possibly it would be better to leave it to user space. If it's common enough, then syntax sugar makes sense (so that user's don't have to constantly import that Either way, I think I'd like to keep in the |
@zenparsing meta-properties are different for a few reasons:
|
But
Bound functions are all wrappers. So I'm just not understanding the arguments. I think we'll have to agree to disagree for now. Let's let this settle for a few days and see how it looks. Thanks for all the feedback though! |
@zenparsing agree, not saying it can't go in, but staunchly against it going in the same proposal. Will get back to this on Thursday |
I think you got your statements backwards - you are binding that generic newer method to the constructor, like My thoughts were coming from the following scheme: x::foo(…) // == foo.bind(x)(…)
// == foo.[[call]](x, …)
new::foo(…) // == new foo(…)
// == foo.[[construct]](…) but I've come to the conclusion that neither is really logical. Maybe making your generic
that should be overwritten by classes (via |
I don't think |
I did, thanks : )
Nah, neither of those is really much of an improvement over the current situation as far as passing constructor factories around, since you would have to auto-bind
|
Disagree,
Too many chances for confusion, please keep your proposal clean. I have listed more than 5 ways it can be confusing. Alternatives already exist for handling Falling back upon meta-properties as a reason that this makes sense seems a bit counter-intuitive. Meta properties are exposing VM state in a way consistent with existing state inspection. Function binding is partially applying (only the this value) of functions, which is already doable today, but lacks sugar. This is new syntax and would be the first time we have a RHS meta identifier. I want a nicer function binding syntax, not one that introduces yet another exception to remember. Just wait for MDN: The I have a poll in twitter (that I am not participating in), but am trying to gather votes one way or another on if the exception seems reasonable to other programmers. |
@bmeck It technically is, but in a sense, it's binding |
@isiahmeadows if this was true, the left hand only |
@bmeck I was referencing the And BTW, Java has the same exact syntax for contructor references: class Averager implements IntConsumer {
private int total = 0;
private int count = 0;
public double average() {
return count > 0 ? ((double) total) / count : 0;
}
public void accept(int i) {
total += i;
count++;
}
public void combine(Averager other) {
total += other.total;
count += other.count;
}
}
Averager averageCollect = roster.stream()
.filter(p -> p.getGender() == Person.Sex.MALE)
.map(Person::getAge)
.collect(Averager::new, Averager::accept, Averager::combine);
System.out.println("Average age of male members: " +
averageCollect.average()); That was kinda my inspiration. But in all honesty, even though I came up with the syntax, I noted in the PR that I wasn't really holding on tight to it. I was more concerned about functionality than ergonomics. |
@isiahmeadows my argument is that:
Resulting in a different behavior is confusing. Thats a lot of edge casing, just to avoid making a generic way to call constructor functions. Sure it looks nice, but I think it is out of scope for the initial proposal. If you want to specify a hidden Specifying |
I've moved the bound constructor stuff into a "Future Extensions" section. I've left the lookahead restriction in the grammar to allow support if we ever want it. |
I think since there is seemingly a lot of debate about ::new then it's sensible to avoid it from the bind specification. A somewhat related question to this debate, I have been making a lot of use of this new operator (back since abstract references) and plan to release libraries next year that imply using the bind operator, whilst things like babel are making it easy to use this now, I was looking around at what other 'near js' ecosystems are planning, such as typescript, one thing I noticed was that under the stage0 proposals for ecma262, the bind operator isn't flagged as being ready: https://github.com/tc39/ecma262/blob/master/stage0.md Looking here there don't seem to be any blocking issues for the core binding operator syntax and was wondering if there are plans for how the operator will progress to the next stage, and if there is anything myself or anyone else can do to help here? Thanks in advance, |
The main reason for ::new was a conceptual "binding the constructor" to On Thu, Dec 24, 2015, 07:56 meandmycode [email protected] wrote:
|
Closing this out, since we'd moved it to the "future extensions" section. |
Isn't
ambiguous with regard to
Foo::new
, shouldn't it be something more likenew::Foo
?The text was updated successfully, but these errors were encountered: