in reply to WWW::Mechanize::Chrome : how to terminate JS code in eval() and return? (OT JS)

this is rather in JS question... you should mark the title with (OT JS)

principally you are looking for "goto" like constructs.

AFAIK those are in JS

(@all: please feel free to extend if I forgot something)

IMHO your function solution is the canonical approach, I'd just prefer an anonymous function to avoid potential conflicts with another "xxx".

(function (){if(1){console.log("aaa"); return;} console.log("bbb");})( +);

(function(){...})() is analogous to sub {...}->() in Perl.

If you are worried about the boilerplate, use Perl to wrap the (function(){...})() part around it and extend the class with a new method.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^2: WWW::Mechanize::Chrome : how to terminate JS code in eval() and return? (OT JS)
by bliako (Abbot) on Apr 12, 2019 at 12:38 UTC

    Thank you. I will go the function way.