class - What's the proper way to declare a field holding a function in dart? -


imagine silly class this:

class conditionalworker{  var validitychecker= (inputs)=>true;  conditionalworker(this.validitychecker)  ... 

now question is, proper way of declaring validitychecker field?

this tutorial suggests using typedefs. that's not practical. firstly it's chore write lot of typedefs used once. , secondly these typedefs show , pollute autocompletion of ide.

the var works best, custom setters/constructor arguments keep of specific kind, know it's discouraged style guide.

i function<bool> more glorified var , amount of work same.

it's shame because it's legal have function this:

 bool every(bool test(e element)); 

where parameter defined function, can't have field declared same way:

bool test(e element); 

but there didn't figure out. right?d

if function<bool> not specific enough (you want specify number , type of arguments have use typedefs. there no other ways.

i'm not sure why think not practical. if want specify type field references value have use 1 of existing classes or create new one. it's same fields referencing functions.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -