@@ -48,7 +48,11 @@ import { arityCheck, typeCheck } from './utils.js';
4848 * ```
4949 */
5050class Functions {
51+ /**
52+ * A set of all the custom functions available in this and all child classes.
53+ */
5154 public methods : Set < string > = new Set ( ) ;
55+
5256 /**
5357 * Get the absolute value of the provided number.
5458 *
@@ -528,14 +532,32 @@ class Functions {
528532 return Object . values ( arg ) ;
529533 }
530534
535+ /**
536+ * Lazily introspects the methods of the class instance and all child classes
537+ * to get the names of the methods that correspond to JMESPath functions.
538+ *
539+ * This method is used to get the names of the custom functions that are available
540+ * in the class instance and all child classes. The names of the functions are used
541+ * to create the custom function map that is passed to the JMESPath search function.
542+ *
543+ * The method traverses the inheritance chain going from the leaf class to the root class
544+ * and stops when it reaches the `Functions` class, which is the root class.
545+ *
546+ * In doing so, it collects the names of the methods that start with `func` and adds them
547+ * to the `methods` set. Finally, when the recursion collects back to the current instance,
548+ * it adds the collected methods to the `this.methods` set so that they can be accessed later.
549+ *
550+ * @param scope The scope of the class instance to introspect
551+ */
531552 public introspectMethods ( scope ?: Functions ) : Set < string > {
532553 const prototype = Object . getPrototypeOf ( this ) ;
533- const ownName = prototype . constructor . name ;
534554 const methods = new Set < string > ( ) ;
535- if ( ownName !== ' Functions' ) {
555+ if ( this instanceof Functions ) {
536556 for ( const method of prototype . introspectMethods ( scope ) ) {
537557 methods . add ( method ) ;
538558 }
559+ } else {
560+ return methods ;
539561 }
540562
541563 // This block is executed for every class in the inheritance chain
0 commit comments