javascript中的闭包
JS中的闭包写法跟python的很类似
function lazy_sum(x) { var sum = function (y) { return x*x+y*10; } return sum; } var f = lazy_sum(1); f(5);
运行结果是:
function lazy_sum(x) { var sum = function (y)... return sum; } var f = lazy_sum(1); f(5); 51
JS中的闭包写法跟python的很类似
function lazy_sum(x) { var sum = function (y) { return x*x+y*10; } return sum; } var f = lazy_sum(1); f(5);
运行结果是:
function lazy_sum(x) { var sum = function (y)... return sum; } var f = lazy_sum(1); f(5); 51