#2924 ES Func.callList()

SlimerDude Sat 20 Jul

Hiya, for completeness it may be nice if Func.callList() (in ES) also handles normal functions as well as funcs from Methods.

I believe the following should support it.

diff --git a/src/sys/es/fan/Func.js b/src/sys/es/fan/Func.js
index d469adc..28afb41 100644
--- a/src/sys/es/fan/Func.js
+++ b/src/sys/es/fan/Func.js
@@ -38,12 +38,9 @@ class Func extends Obj {
 // Methods
 //////////////////////////////////////////////////////////////////////////
 
-  static call(f, ...args) {
-    if (f.__method) return f.__method.call(...args);
-    return f(...args);
-  }
-  static callOn(f, obj, args) { return f.__method.callOn(obj, args); }
-  static callList(f, args) { return f.__method.callList(args); }
+  static call(f, ...args)     { return f.__method ? f.__method.call(...args)     : f(...args); }
+  static callOn(f, obj, args) { return f.__method ? f.__method.callOn(obj, args) : throw UnsupportedErr.make(); }
+  static callList(f, args)    { return f.__method ? f.__method.callList(args)    : f.apply(null, args.__values); }
 
   static params(f) {
     if (f.__params) return f.__params;

Gary Sun 21 Jul

Cool stuff!

matthew Wed 24 Jul

Pushed an enhancement for this.

SlimerDude Thu 25 Jul

Thanks @Matthew!

I should have mentioned, I added the UnsupportedErr to Func.callOn() to satisfy the docs:

Func.callOn()

... Throw UnsupportedErr if called on a function which is not an instance method.

Login or Signup to reply.