javascript - can you add properties on to functions in Dart? -


can add properties on functions in dart? tried this:

void main(){      fn(){         //dosomething     };      fn.id = 1; //exception nosuchmethod  } 

only nosuchmethod exception thrown. there way add properties functions or type of object matter @ runtime in javascript?

(also why saying no such method exception when i'm assigning property?)

you can not add property on function. can define object can call function (see emulating functions in dart). here's example :

class wannabefunction {   var id;   call(int a, int b) => + b; }  main() {   var wf = new wannabefunction();   wf.id = 1;   wf(3, 4); // 7 } 

for nosuchmethoderror : when use fn.id = 1 call implicite setter id= on fn. why error.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -