Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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 - Fatal编程技术网

Javascript 调用对象构造函数时出错

Javascript 调用对象构造函数时出错,javascript,html,Javascript,Html,嗨,我想创建一个新的blob对象: function Blob(X,Y,R) { this.x = X; this.y = Y; this.r = R; this.show = function (ctx) { ctx.arc(this.x,this.y,this.r,0,2*Math.PI,false); ctx.fill(); } this.moveTo = function(x,y,ctx){ ctx.strokeStyle = "#ffffff" ct

嗨,我想创建一个新的blob对象:

function Blob(X,Y,R) {
this.x = X;
this.y = Y;
this.r = R;

this.show = function (ctx) {
    ctx.arc(this.x,this.y,this.r,0,2*Math.PI,false);
    ctx.fill();
}

this.moveTo = function(x,y,ctx){
    ctx.strokeStyle = "#ffffff"
    ctx.arc(this.x,this.y,this.r,0,2*Math.PI,false);
    ctx.fill();
    ctx.strokeStyle = "#000000"
    ctx.arc(x,y,r,0,2*Math.PI,false);
    ctx.fill();
}

    var myBlob = new Blob(250,250,50);
    blob.show(ctx);
创建对象时,会收到一条错误消息:


未捕获类型错误:构造“Blob”失败:第一个参数既不是数组,也没有索引属性。

您需要提供完整代码

在这里,您没有名为Blob的类。也没有名为show的函数

也许可以看一看,了解更多信息

class BlobClass {
  constructor(x, y, r) {
   this.x = x;
   this.y = y;
   this.r = r;
  }

  get show() {
    ctx.strokeStyle = "#ffffff"
    ctx.arc(this.x,this.y,this.r,0,2*Math.PI,false);
    ctx.fill();
  }
}

const blob = new BlobClass(10, 10, 10);

blob.show()

这应该和我想的一样。您可能不应该为类Blob命名,因为这是buildt in功能的名称。

不确定您想要实现什么,但错误消息表明您在创建Blob时传递了错误的参数。例如,您可以传递一个列表,以便创建一个blob:

var myBlob = new Blob([250,250,50]);

但请提供更多细节。

这不是
Blob
的工作原理。仔细阅读文档。不太清楚你想在这里做什么。您正在尝试创建实际的Blob:?如果是这样的话,这些论点是不正确的,我敢肯定你不会这么做。好吧,sry的家伙们只是想象BLOB会是圆圈,或者干脆把我的类命名为BLOB