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

标签 javascript dojo

在 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/

相关文章:

使用 nodejs 时的 JavaScript 命名约定

Javascript - 隐藏的数学答案。

使用 'function' 解析字符串的 Javascript

javascript - 将 DropDown 字符串从 View 传递到 Controller 方法

jquery - Dojo 相当于 $(document).scrollTop?

javascript - 在 Z 轴( Highcharts )气泡图上显示百分比值

javascript - 填充 dojo dijit 组合框

javascript - Dojo 折线图上的自定义标记/工具提示

javascript - 如何使用 Angular 二绑定(bind)来动态创建 Kendo 网格?

javascript - 如何将 JsonRestStore 与我的 RESTful 服务结合使用