time 6m25s
    image.png

    get set
    time 10m43s
    image.png
    set代替了writeable

    time 12m54s

    time 15m58s

    1. var obj = {
    2. get a() {
    3. return 5;
    4. },
    5. set a(val) {
    6. this.a = val;
    7. }
    8. }
    9. // obj.a=10;
    10. /*RangeError: Maximum call stack size exceeded*/
    11. console.log(obj.a);//5
    1. var obj = {
    2. get a() {
    3. return 5;
    4. },
    5. set a(val) {
    6. this.a = val;
    7. }
    8. }
    9. obj.a=10;
    10. /*RangeError: Maximum call stack size exceeded
    11. * 执行set操作,set操作中继续调用set操作,无限循环*/
    12. // console.log(obj.a);//5

    time 19m
    一般都这样写

    1. var obj = {
    2. _a: 5,
    3. get a() {
    4. return this._a;
    5. },
    6. set a(val) {
    7. this._a = val;
    8. }
    9. }
    10. obj.a = 10;
    11. console.log(obj.a);//10 设置成功

    writeable等都是源操作,共有4种,多么,不多。

    time 22m23s

    1. var obj = {};
    2. var _a = 5;
    3. Object.defineProperty(obj, "a", {
    4. get() {
    5. return _a;
    6. },
    7. set(val) {
    8. console.log(this);
    9. this._a=val;
    10. /*这样设置还是5,_a是外界的,不是内部的,相当于obj新建了一个_a*/
    11. // _a = val;
    12. }
    13. })
    14. obj.a = 10;
    15. console.log(obj.a);//5

    image.png

    1. var obj = {};
    2. var _a = 5;
    3. Object.defineProperty(obj, "a", {
    4. get() {
    5. return _a;
    6. },
    7. set(val) {
    8. console.log(this);
    9. this._a=val;
    10. /*这样设置还是5,_a是外界的,不是内部的*/
    11. _a = val;
    12. }
    13. })
    14. obj.a = 10;
    15. console.log(obj.a);//10

    time 26m10s

    1. var pipe = function (value) {
    2. var arr = [];
    3. var proxy = new Proxy(
    4. {},
    5. {
    6. get(target, property, receiver) {
    7. if (property === 'get') {
    8. // console.log(arr);
    9. // arr.reduce((pre,item,index)=>{},value,)
    10. return arr.reduce((val, fn) => {
    11. return fn(val);
    12. }, value)
    13. return;
    14. }
    15. ;
    16. arr.push(window[property]);
    17. return receiver;
    18. }
    19. }
    20. );
    21. return proxy;
    22. };
    23. var double = n => n * 2;
    24. var pow = n => n * n;
    25. var reverseInt = n =>
    26. n
    27. .toString()
    28. .split("")
    29. .reverse()
    30. .join("");
    31. console.log(pipe(3).double.pow.reverseInt.get)

    time 42m39
    image.png

    time 57m43s
    image.png
    image.png