Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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/2/cmake/2.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—var DndUpload=function(inputElem){}的含义;_Javascript_Javascript Objects - Fatal编程技术网

JavaScript—var DndUpload=function(inputElem){}的含义;

JavaScript—var DndUpload=function(inputElem){}的含义;,javascript,javascript-objects,Javascript,Javascript Objects,请允许我解释一下: 下面的代码代表什么?它是否创建了DNDUPT?或者,它是否创建了一个DndUpload()函数?我错过的是JavaScript对象创建过程中通常出现的语句new。我很困惑,请你给我解释一下好吗 var DndUpload = function (inputElem) { this.input = inputElem; this.dropZone = null; this.isDragging = false; this.init(); };

请允许我解释一下:

下面的代码代表什么?它是否创建了DNDUPT?或者,它是否创建了一个DndUpload()函数?我错过的是JavaScript对象创建过程中通常出现的语句
new
。我很困惑,请你给我解释一下好吗

var DndUpload = function (inputElem)
{
    this.input = inputElem;
    this.dropZone = null;
    this.isDragging = false;
    this.init();
};
据我所知,这是在Javascript中创建对象的方法:

var myObject = new function()
{
};

如果你和解释有任何联系,那会有帮助的。谢谢。

这是一种更糟糕的写作方式:

function DndUpload(inputElem)
{
    this.input = inputElem;
    this.dropZone = null;
    this.isDragging = false;
    this.init();
}
这是一个很好的例子。它不会创建
DndUpload
的实例。从技术上讲,它确实创建了一个对象,其名称是
DndUpload
和。要创建此“类”的实例:


这是一种更糟糕的写作方式:

function DndUpload(inputElem)
{
    this.input = inputElem;
    this.dropZone = null;
    this.isDragging = false;
    this.init();
}
这是一个很好的例子。它不会创建
DndUpload
的实例。从技术上讲,它确实创建了一个对象,其名称是
DndUpload
和。要创建此“类”的实例:


你的代码本质上是为一个“类”创建一个构造函数,它或多或少是一个对象的蓝图

然后将该构造函数放入名为
DndUpload

现在,您可以使用

var myObject = new DndUpload(input elem)

你的代码本质上是为一个“类”创建一个构造函数,它或多或少是一个对象的蓝图

然后将该构造函数放入名为
DndUpload

现在,您可以使用

var myObject = new DndUpload(input elem)
定义匿名构造函数,然后使用匿名构造函数实例化新对象。它可以被替换为
var myObject={}

var DndUpload = function (inputElem)
{
    this.input = inputElem;
    this.dropZone = null;
    this.isDragging = false;
    this.init();
};
定义一个构造函数(从技术上讲是一个分配给变量的匿名构造函数)。然后,您可以通过使用
new
调用构造函数来创建此“类”的对象:

var dndUploadObject = new DnDUpload(),
    anotherUploadObject = new DnDUpload(); //2 unique DnDUpload objects
定义匿名构造函数,然后使用匿名构造函数实例化新对象。它可以被替换为
var myObject={}

var DndUpload = function (inputElem)
{
    this.input = inputElem;
    this.dropZone = null;
    this.isDragging = false;
    this.init();
};
定义一个构造函数(从技术上讲是一个分配给变量的匿名构造函数)。然后,您可以通过使用
new
调用构造函数来创建此“类”的对象:

var dndUploadObject = new DnDUpload(),
    anotherUploadObject = new DnDUpload(); //2 unique DnDUpload objects

你的答案在这里:@EnesUnal:+1,你好,谢谢你的评论。这很有帮助,尽管答案部分的解释也很有帮助。你的答案在这里:@EnesUnal:+1,你好,谢谢你的评论。这很有帮助,尽管答案部分的解释也很有帮助。+1,谢谢你的回答。它帮助我很好地解释了这个问题。它帮助我很好地解释了这个问题。这是一个很好的解释。它清楚地回答了我的问题。感谢您提供的附加链接。它们为你的答案增加了价值。+1,谢谢你的即时回答。这是一个很好的解释。它清楚地回答了我的问题。感谢您提供的附加链接。他们为你的答案增加了价值。谢谢你的回答。尽管所有的答案都非常好,但在我看来,这个答案最好地描述了我的问题。尤其是关于匿名构造函数的信息对我来说是新的。我将此答案标记为已接受答案。再次谢谢你。谢谢你的回答。尽管所有的答案都非常好,但在我看来,这个答案最好地描述了我的问题。尤其是关于匿名构造函数的信息对我来说是新的。我将此答案标记为已接受答案。再次感谢你。