JavaScript::Function - Reference to a JavaScript function


JavaScript documentation Contained in the JavaScript distribution.

Index


Code Index:

NAME

Top

JavaScript::Function - Reference to a JavaScript function

DESCRIPTION

Top

Functions in JavaScript are actually Function-objects. This class encapsulates them and make them invokeable as a code-reference from Perl.

INTERFACE

Top

INSTANCE METHODS

as_function

Returns an code-reference that can be invoked which calls the underlying JavaScript Function-object.

OVERLOADED METHODS

Instances of this class overloads &{} which means that you can use the instance as a code-reference directlly without having to use as_function.


JavaScript documentation Contained in the JavaScript distribution.

package JavaScript::Function;

use strict;
use warnings;

our @ISA = qw(JavaScript::Boxed);

use overload '&{}'  => 'as_function', fallback => 1;

sub as_function {
    my $self = shift;
    return sub { $self->context->call( $self, @_ ) };
}

1;
__END__