简体   繁体   中英

Can't access member data Three.js TypeScript

I'm using three.d.ts from DefinitelyTyped and TypeScript. I have the following code

class WoodStyle extends THREE.MeshBasicMaterial{
    putTexture(image: any){
        super.map=image;
    }
    constructor(){
        LoadImage().then(putTexture);
        super();
    }
}

In which I load an image and then I update the material with the new image. But when I'm trying to compile the code it shows an error: 2340 Only public and protected methods of the base class are accessible via the 'super' keyword . What I'm doing wrong?

When accessing an inherited property, use this :

class WoodStyle extends THREE.MeshBasicMaterial{
    putTexture(image: any){
        this.map=image;
    }
    constructor(){
        LoadImage().then(putTexture);
        super();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM