Dart equivalent of Ruby's instance_eval -


ruby has neat method called instance_eval allows evaluating block of code in context of specific instance. great because 1 can use same block of code in different contexts , different results based on how context defines methods. there equivalent in dart? in other words can take method class , attach , execute on instance in class or define method letting user pass in code corresponding method. know limited form of possible emulate subclassing.

it seems there no possibility of doing in dart. use several approaches, depending on needs:

  1. creating function context argument of function:

    somefunction (context, arg1, arg2) { ... }

  2. using mixins: https://www.dartlang.org/articles/mixins/

  3. using generics: https://www.dartlang.org/articles/optional-types/#generics

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -