hyTags
HomeHome DocumentationDocumentation

javascript-call

Calls a JavaScript function with arguments produced by commands.
Parameter
Type
Description
function
String
Name of the function to call. Can be a dotted path for global functions (e.g., "Math.max") or a method name when used with a receiver.
receiver
T?
Optional object to call the method on. If not provided, the function is treated as a global function.
return
Type?
The expected return type. If not specified, the call returns void.
commands
Commands
Commands that produce the arguments to pass to the function. Each command's result becomes one argument.
return
T
The result of the function call, typed according to the return parameter. Returns void if no return type is specified.
Test Case:Call global function with arguments
    <div></div>
    
    <javascript-call function="Math.max" return="number">
      <number-new value="1">
      <number-new value="5">
      <number-new value="3">
    </javascript-call>
    <assert-equal value="5" type="number">
    
    👆 Try to change something!
  • Test Case:Call global function Math.min
      <div></div>
      
      <javascript-call function="Math.min" return="number">
        <number-new value="10">
        <number-new value="2">
      </javascript-call>
      <assert-equal value="2" type="number">
      
      👆 Try to change something!
    • Test Case:Call method on receiver
        <div></div>
        
        <string-new value="hello world">
        <javascript-call function="toUpperCase" $receiver return="string"></javascript-call>
        <assert-equal value="HELLO WORLD" type="string">
        
        👆 Try to change something!
      • Test Case:Call DOM element method
          <div id="some-id"></div>
          
          <selection-get-element>
          <javascript-call function="hasAttribute" $receiver return="bool">
            <string-new value="id">
          </javascript-call>
          <assert-equal value="true" type="bool">
          
          👆 Try to change something!
        • Test Case:Call method on DateTime
            <div></div>
            
            <date-time-new year="2025" month="12" day="19">
            <javascript-call function="getFullYear" $receiver return="number"></javascript-call>
            <assert-equal value="2025" type="number">
            
            👆 Try to change something!
          • Test succeeded Test failed