一、概念:
1.閉包:
內部函式對外部函式作用域變數的引用
2.裝飾器:
在不影響原有函式的功能,還能新增新的功能
二、閉包詳解:
1.函式內部的函式無法直接呼叫
函式內的屬性,都是有生命週期,都是在函式執行期間

2.將內部函式return出來,可以供外部函式呼叫

3.閉包:函式內的閉包函式私有化變數,完成了資料的封裝

4.閉包的作用:可在函式執行過程中儲存所需要的值
但大量應用會有記憶體的損耗

三、裝飾器(語法糖)詳解:
1.裝飾器函式的工作流程:
(1)原函式上使用@裝飾器函式實現原函式功能的補充
(2)裝飾器的入參為原函式的物件
(3)裝飾器函式的內部函式返回了原函式的呼叫
(4)裝飾器函式的返回值為內部函式名
2.裝飾器函式示例:
通過在原函式上myprint@裝飾器函式func1,實現對myprint函式功能的補充

3.裝飾器函式應用擴充套件
帶引數的裝飾器,裝飾多個函式
