SOURCE

const arrayProto = Array.prototype;
const arrayMethods = Object.create(arrayProto)

    ;[
        'push',
        'pop',
        'shift',
        'unshift',
        'splice',
        'sort',
        'reverse'
    ]
        .forEach(function (method) {
            const original = arrayProto[method];
            Object.defineProperty(arrayMethods, method, {
                value: function mutator(...args) {
                    const result = original.apply(this, args);
                    const ob = this.__obj__;
                    let inserted;
                    switch (method) {
                        case 'push':
                        case 'unshift':
                            inserted = args
                            break;
                        case 'splice':
                            inserted = args.slice(2)
                            break;
                    }
                    if (inserted) ob.observeArray(inserted);
                    ob.dep.notify()
                    return result;
                },
                enumerable: false,
                writable: true,
                configurable: true

            })

        })
console 命令行工具 X clear

                    
>
console