我毫不困惑地理解了关于perl闭包的工作原理,就像下面这个例子一样。
我正在尝试理解下一段Javascript代码:
下一个
use 5.012;
use strict;
use warnings;
sub countdown {
my $start = shift;
return sub { $start-- }
}
my $c10 = countdown(3);
say while( $_ = $c10->() );
我正在尝试理解下一段Javascript代码:
var runInSandbox = (function(js, inputPath) {
(function() {
if ((!context.initialized__QUERY)) {
return createContext();
};
})();
(function() {
if (typeof(inputPath) !== 'undefined') {
(process.argv)[1] = inputPath;;
(context)["__dirname"] = path.dirname(inputPath);;
return (module)["filename"] = inputPath;;
};
})();
return vm.runInContext(js, context, "sibilant");
});
没有机会!:( 请有人将上述内容改写为 perl ?我了解一些 Perl,因此对于我来说,理解 JS 基础知识和如下结构将非常有用:
(...)() - more precisely
(function(){.....})()
双倍 ((
在if语句中
if ((!context.initialized__QUERY)) {
下一个
(context)["__dirname"] = something ;;
或者
return (module)["filename"] = inputPath;; // why double ;;?
如果有人能向我推荐像这样的资源: Perl程序员学习JavaScript
- 那就太好了 ;)
附注:JS(缩写)来自此处:https://github.com/jbr/sibilant/blob/master/lib/cli.js