登录后复制 const calculator = { count: 0, next() { return ++this.count }, double(a) { return a * 2 }, add(a, b) { return a + b } } calculator.add(2, 3) // function logging(fn){ // fn.call() // } function logging(obj) { for (const key in obj) { const atr = obj[key] if (typeof atr === 'function') { obj[key] = function (...args) { console.log(atr.name) const ret = atr.apply(this, args) console.log(ret) } } } } logging(calculator) calculator.double(3) 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31. 原创作者: u_15698937 转载于: https://blog.51cto.com/u_15698937/11533371