闭包:closure
function html_tag(tag){
function wrap_text(msg){
console.log('<' + tag +'>' + msg + '</' + tag + '>')
}
return wrap_text
}
print_h1 = html_tag('h1')
print_h1('Test Headline!')
print_h1('Another Headline!')
html_tag函数已经结束调用,但是
print_h1仍然保持着对tag变量的访问,这种现象叫闭包。
first-class function
把函数当成object,可以作为函数参数/返回值等
decorator
decorator就是改变函数的行为,附加一些功能
decorator的实现基于closure
标签:closure,function,python,h1,html,tag,print,decorator From: https://blog.csdn.net/weixin_45124463/article/details/139014069