1
FeifeiJin 2020-03-26 01:06:22 +08:00 via Android
eval 理论上可以的
|
2
xcstream OP 百度了一下 解决了
const { MethodMissingClass } = require('unmiss') class Add extends MethodMissingClass { methodMissing(name, ...args) { return Number(name.substr(3)) + args[0] } } const A = new Add; const r = A.add1000(1) console.log(r) |
3
seki 2020-03-26 01:37:36 +08:00
基本就是 proxy 的玩法
``` import _ from 'lodash' const wrapped = {} const proxy = new Proxy(wrapped, { get(target, p, val) { if (_.isString(p) && _.startsWith(p, 'add')) { const v = parseInt(p.replace('add', ''), 10) return q => q + v } } }) console.log(proxy.add100(1)) ``` |