-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support object literals or anonymous classes #1089
Comments
Set owner to @gbracha. |
We may consider object literals in due course. Renaming the issue since it has nothing to do with the title. Removed Type-Defect label. |
Issue #3028 has been merged into this issue. |
You can emulate this easily enough with a class being constructed with a closure argument to capture scope etc. Benefit outweighed by complexity. Added WontFix label. |
This comment was originally written by @tomyeh Sorry, I don't get it. Would you show me the sample code equivalent to anonymous classes? For example, how to do the following code in Dart? Thanks. return new Iterator<String>() { |
This comment was originally written by [email protected] Tom, I already started a thread about this issue. https://groups.google.com/a/dartlang.org/forum/#!topic/misc/rUWJMuDfJWc |
Bummer this didn't happen. |
I guess we're trying to go the Java route here 😓 Put the complexity on the end user instead of designing software correctly - bravo |
This issue was originally filed by [email protected]
In JavaScript Partial Application and Currying is wellknown. Things like this are possible:
{{{code}}}
numberGame() {
var secretNumber = 21;
return () {
guess(g) {
if(g == secretNumber) {
return "Correct";
} else {
return "Try again";
}
}
};
}
main() {
var game = numberGame();
print( game.guess(45) );
}
{{{code}}}
This is not possible with Dart, because in this case JavaScript would return an Object with a new function.
As an alternative approach, Dart might be benefit from implementing anonymous classes. Like:
{{{code}}}
interface A {
void doSomething();
}
myFunction() {
return new A() {
void doSomething() {
// do something
}
}
}
numberGame() {
return new Dynamic() {
int guess(g) {
}
}
}
{{{/code}}}
This is a known appoach even in the Java World.
Please see:
https://groups.google.com/a/dartlang.org/group/misc/browse_thread/thread/891044daf1754150
The text was updated successfully, but these errors were encountered: