es6 js proxy 增强对象和函数(方法)生命周期 预处理

js yekong 652℃
let pro = new Proxy({
    add: function (val) {
        return val + 100;
    },
    name: 'i am '
}, {
    get: function (target, key, property) {
        console.log('come in get')
        return target[key]
    },
    set: function (target, key, value, receiver) {
        console.log(`setting ${key}=${value}`)
        return target[key]=value;
    }
})
console.log(pro.name)
pro.name = 'ceshi'
console.log(pro.name)
let target = function () {
    return 'im'
}
let handler = {
    apply(target, ctx, args) {
        console.log('do apply')
        return Reflect.apply(...arguments)
    }
}
let pro = new Proxy(target, handler);
console.log(pro())

喜欢 (0)