函数进行控制台重写

function getParameterByName() {
console.log('1');
alert('2');
};

function getParameterByName(){
console.log(“1”);
“);
};

b = getParameterByName.toString();
b=b.replace(/alert\('2'\)/, "");
// 将b转换为函数对象并赋值给c
c = eval('(' + b + ')');

B = getParameterByName.toString();
B=B.replace(/alert\('2 '\)/,“”);
// 将B转换为函数对象并赋值给c
c = eval(“(”+ B +");

 

 

 

const originalFunction = () => {
  console.log('Original function');
}

// 创建一个 Proxy 对象来拦截函数的调用
const proxy = new Proxy(originalFunction, {
  // 定义拦截处理函数
  apply: (target, thisArg, argumentsList) => {
    console.log('Before invocation');
    // 调用原始函数
    const result = Reflect.apply(target, thisArg, argumentsList);
    console.log('After invocation');
    return result;
  }
});

// 调用被代理的函数
proxy();
posted @ 2024-01-16 12:25  一直闭眼看世界  阅读(8)  评论(0编辑  收藏  举报