gpt4 book ai didi

javascript - 使用 dojo 的声明函数 : what is the first parameter?

转载 作者:行者123 更新时间:2023-11-30 15:01:04 26 4
gpt4 key购买 nike

在 dojo 中使用 declare 时,我有时会看到两种略有不同的方法:

方式一是

define(["dojo/_base/declare"], function(declare){
return declare(null, {
constructor: function(){

}
});

对比

define(["dojo/_base/declare"], function(declare){
return declare("some/string/with/slashes/parameter",null, {
constructor: function(){

}
});

想知道第二版的"some/string/with/slashes/parameter"是什么原因?

模块/“dojo 类”是否需要为自己命名,或者命名并不总是由其文件名暗示?

最佳答案

第一个声明将创建一个匿名类(仅在其作用域内可用),因此要访问最后一个,您应该在 dojoConfig 全局变量中访问它或它的包,

对于最后的第二个声明,它是在全局范围(应用程序范围)中创建的,因此可以使用其声明的类名 some.string.with.slashes.parameter 实例化或使用它(建议使用点而不是斜杠)一般定义包含此类 + 类名的 namespace 。

不是在道场documentation :

Named classes should only be created if they will be used with the Dojo parser. All other classes should omit the className parameter.

这意味着仅将第二个声明用于与 dojo/parser 一起使用的小部件或类,例如创建 Button 的自定义声明(ovveride 或 extend )...

关于javascript - 使用 dojo 的声明函数 : what is the first parameter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46527439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com