相关疑难解决方法(0)

在代理处理程序中,如何区分获取属性(var)与调用方法?

我有以下代码,其中我使用代理对象(代理)来尝试捕获方法调用和属性访问:

示例: https: //jsfiddle.net/r8j4fzxL/2/

(function() {
    'use strict';
    console.clear();

    //some empty class where I want to trap methods props
    class X {
        //...
    }

    let proxy = {
        get: function(target, prop, receiver) {

            console.log('get called: ',
                'target:', target,
                'prop:', prop,
                'receiver:', receiver
            );
            //this is OK, if we are called as a method.
            //but it isn't when called as .prop - because, obviously, we return a function here.
            return function(...args) {
                console.log('wrapper args:', args);
                return 42;
            }
        },


    };


    let …
Run Code Online (Sandbox Code Playgroud)

javascript ecmascript-6

4
推荐指数
1
解决办法
2267
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1