Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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 dojodeclare中可选className参数的用途是什么?_Javascript_Dojo - Fatal编程技术网

Javascript dojodeclare中可选className参数的用途是什么?

Javascript dojodeclare中可选className参数的用途是什么?,javascript,dojo,Javascript,Dojo,DOJO中的declare(类名、超类、道具)中的className有什么用途 在下面的示例中,我尝试在heritage中使用className 传递className时,我收到一个错误 declare(className,superclass,props); className Optional The optional name of the constructor (loosely, a "class") stored in the "declaredClass" property i

DOJO中的
declare(类名、超类、道具)
中的
className
有什么用途

在下面的示例中,我尝试在heritage中使用className

传递
className
时,我收到一个错误

declare(className,superclass,props);

className Optional
The optional name of the constructor (loosely, a "class") stored in the "declaredClass" property in the created prototype. It will be used as a global name for a created constructor.


我不确定您收到了什么错误,但是
className
参数本质上只是出于遗留原因。声明的类被放置在具有该名称的全局变量中,但是当您使用AMD时,您并不真正需要它

例如,如果您已经这样做:

var Dog = declare('MyLibrary.Doggie', Mammal, {
    makeNoise: function() {
        loglog("Waf waf"); //console.log("Waf waf");
    }
});
将创建一个名为
MyLibrary
的全局对象,其中包含名为
Doggie
的成员。然后,你可以写:

var myDog = new MyLibrary.Doggie("Pluto"); // instead of Dog("Pluto");
myDog.sayName();
myDog.makeNoise();
不过,我认为现在没有任何理由这么做,所以您应该忽略className参数

var Mammal = declare(null, { .... });
var Dog = declare(Mammal, { .... });

是的,事实上我已经删除了类名,它工作得很好。感谢您的解释有用的文章:
var Mammal = declare(null, { .... });
var Dog = declare(Mammal, { .... });