【问题标题】:Can't access member data Three.js TypeScript无法访问成员数据 Three.js TypeScript
【发布时间】:2015-05-13 19:29:50
【问题描述】:

我正在使用来自definitelyTyped 和TypeScript 的三个.d.ts。我有以下代码

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

我在其中加载图像,然后使用新图像更新材料。但是当我尝试编译代码时,它会显示一个错误:2340 Only public and protected methods of the base class are accessible via the 'super' keyword。我做错了什么?

【问题讨论】:

  • 如果你扩展MeshBasicMaterialmap 不是你rew class 的属性吗?所以你可以this.map...,不是吗?不是打字稿用户

标签: javascript three.js typescript


【解决方案1】:

访问继承属性时,使用this

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

【讨论】:

    猜你喜欢
    • 2018-11-17
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    相关资源
    最近更新 更多