Skip to content
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

Closed
DartBot opened this issue Jan 8, 2012 · 8 comments
Closed

Support object literals or anonymous classes #1089

DartBot opened this issue Jan 8, 2012 · 8 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Jan 8, 2012

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

@iposva-google
Copy link
Contributor

Set owner to @gbracha.
Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Jan 21, 2012

We may consider object literals in due course. Renaming the issue since it has nothing to do with the title.


Removed Type-Defect label.
Added Type-Enhancement, Accepted labels.
Changed the title to: "Support object literals or anonymous classes".

@gbracha
Copy link
Contributor

gbracha commented May 17, 2012

Issue #3028 has been merged into this issue.

@gbracha
Copy link
Contributor

gbracha commented May 23, 2012

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.

@DartBot
Copy link
Author

DartBot commented May 24, 2012

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>() {
  bool hasNext() {...}
  String next() {...}
};

@DartBot
Copy link
Author

DartBot commented May 24, 2012

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

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels May 24, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
@bugeats
Copy link

bugeats commented May 11, 2020

Bummer this didn't happen.

@AdamSalma
Copy link

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 closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants