SOURCE

function cb() {
    console.log('dom to render')
}
function defineReactive(obj, key, value) {
    Object.defineProperty(obj, key, {
        enumerable: true,
        configurable: true,
        get: function () {
            return value
        },
        set: function (newValue) {
            if (newValue === value) { return }
            cb()
        }
    })
}

function observer(obj) {
    if (!obj || typeof obj !== 'object') { return }
    Object.keys(obj).forEach(key => {
        defineReactive(obj, key, obj[key])
    })
}

class Vue {
    constructor(options) {
        console.log(options.data.name)
        this._data = options.data
        observer(this._data)
    }
}

const o = new Vue({
    data: {
        name: 'js',
        age: '30'
    }
})

o._data.name = 'zzz'

console 命令行工具 X clear

                    
>
console