lundi 23 novembre 2020

For ... in not yielding methods

Given the following:

export class MyClass {
    public dataA = 0
    private dataB = 123
    public myMethod(): any {
        return {
            test: 'true'
        }
    }

    constructor() {
        for (const propOrMethod in this) {
            console.log({propOrMethod})
        }
    }
}

const myInst = new MyClass()

I run this with ts-node index.ts and all i get is:

{ propOrMethod: 'dataA' }
{ propOrMethod: 'dataB' }

With no reference to myMethod. I would like to iterate over all the methods of my class, but they don't appear to exist





Aucun commentaire:

Enregistrer un commentaire