EdwardZZZ / articles

工作点滴记录
2 stars 0 forks source link

prototype.toString #38

Open EdwardZZZ opened 6 years ago

EdwardZZZ commented 6 years ago
class A {
    onLoad() {
        // TODO;;;;
        console.log(111);
    }
}

const a = new A();

// const onLoad = A.prototype.onLoad.toString().replace(/[\r|\t|\n]/g, '');
const onLoad = A.prototype.onLoad.toString().match(/\{([\s\S]*)\}$/i)[1];

console.log(onLoad);

const newOnLoad = new Function(onLoad);

newOnLoad();