perl.javascript...Re: JS closures lose context by Andy Armstrong- November 4, 2006 On 4 Nov 2006, at 20:40, Andy Armstrong wrote:> It looks as if the context that should be captured (closed over) by > the returned JS function is being lost. Is this expected behaviourOh and the &39;return 1&39; in js_next was just me playing to find out exactly what was being lost - but it doesn&39;t affect the observed behaviour.-- Andy Armstrong, hexten.nethttp://www.nntp.perl.org/group/perl.javascript/2006/11/msg52.html JS closures lose context by Andy Armstrong- November 4, 2006 Given this code:----------------------------------------------------!usrbinperl -wuse strict;$ = 1;use JavaScript;my $rt = JavaScript::Runtime->new();my $cx = $rt->create_context();sub get_js my $next = 1; Make a perl function $cx->bind_function(perl_next => sub return $next++; ); $cx->eval(q function makeClosure() var next = 1; var js_next = function() return 1; return next++; .http://www.nntp.perl.org/group/perl.javascript/2006/11/msg51.html |