Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取属性";“质感”;从未定义_Javascript_Html_Webgl - Fatal编程技术网

Javascript 无法读取属性";“质感”;从未定义

Javascript 无法读取属性";“质感”;从未定义,javascript,html,webgl,Javascript,Html,Webgl,我知道这是一个非常常见的问题。我从undefined获取了一个无法读取属性“texture”。很抱歉,我对javascript非常陌生 我的代码的javascript部分如下 this.createTexture=function(Texturename,width,height){ this.Texture[Texturename]=gl.createTexture(); this.Texture[Texturename].name=Texturename; this.Textur

我知道这是一个非常常见的问题。我从undefined获取了一个无法读取属性“texture”。很抱歉,我对javascript非常陌生

我的代码的javascript部分如下

this.createTexture=function(Texturename,width,height){
  this.Texture[Texturename]=gl.createTexture();
  this.Texture[Texturename].name=Texturename;
  this.Texture[Texturename].width=width;
  this.Texture[Texturename].height=height;
  return this.Texture[Texturename,width,height];
}
我正在尝试在webgl部件中创建纹理

如何在webgl中调用createTexture?在这里,我只需输入texturename、宽度和高度,就可以让函数正常工作。我知道这不仅仅是创建一个纹理,它只是一个简单的例子。我试过了,但是不行

function exampleTexture(){
Texture.createTexture("moon",1024,1024);
}
上面说我的错误在线路上

this.Texture[Texturename]=gl.createTexture();

感谢此
引用的对象似乎没有
纹理
属性。在这种情况下:

this.createTexture=function(Texturename,width,height){
  // use this.Texture if available, otherwise init it as an empty object
  this.Texture = this.Texture || {};

  this.Texture[Texturename]=gl.createTexture();
  this.Texture[Texturename].name=Texturename;
  this.Texture[Texturename].width=width;
  this.Texture[Texturename].height=height;
  return this.Texture[Texturename,width,height];
}

注意命名约定:在JS中,camelCase通常用于变量,PascalCase用于构造函数。因此,我将
this.Texture
重命名为
this.textures
并将
Texturename
重命名为
Texturename

是否存在
Texture.Texture
?您将获得
this.Texture
,而
this
是调用其方法的对象的值。对于
Texture.createTexture
,this
的值为
Texture
,因此
this.Texture
Texture.Texture
。我不完全理解你的代码是做什么的,所以我不能提出解决方案。也许你想做
纹理[Texturename]
,在这种情况下你应该做
这个[Texturename]