Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.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 Dojo中未定义this.own_Javascript_Dojo - Fatal编程技术网

Javascript Dojo中未定义this.own

Javascript Dojo中未定义this.own,javascript,dojo,Javascript,Dojo,我正试图在Dojo中使用一个名为loadsth的方法创建一个singleton类。我想在foreach循环中运行this.own。然而,当我运行这段代码时,它说 TypeError: this.own is not a function 我查看了Dojo文档和脚本,其中指出方法“own”是dijit/Destroyable的一部分。但是,尽管它包括在内,但它不起作用。我在//@1和//@2两个位置试过。我实际上需要它在位置/@2,但我想确保foreach循环不会隐藏“this”。所以我尝试了/

我正试图在Dojo中使用一个名为loadsth的方法创建一个singleton类。我想在foreach循环中运行this.own。然而,当我运行这段代码时,它说

TypeError: this.own is not a function
我查看了Dojo文档和脚本,其中指出方法“own”是dijit/Destroyable的一部分。但是,尽管它包括在内,但它不起作用。我在//@1和//@2两个位置试过。我实际上需要它在位置/@2,但我想确保foreach循环不会隐藏“this”。所以我尝试了/@1,但效果不太好

define([
    "dojo/_base/declare",
    "dijit/Destroyable"    
], function (
    declare,
    destroyable
) {
    var SingletonClass = declare("some.Class", null, {

        _registerdPropertyGrids: [],
        _resourceNode: "",

        /*
         * This method is used register a property grid plus
         * provide the properties that should be shown in that 
         * grid. 
         */
        registerWidget: function(widgetName, propertyGridWidget) {
            console.log(widgetName);
            this._registerdPropertyGrids.push({widgetName, propertyGridWidget});
        },

        /*
         * Sets the resource node for this widget.
         */
        setResourceNode: function(resourceNode) {
            this._resourceNode = resourceNode;
        },

        /*
         * Loads sth.
         */
        loadSth: function() {
            console.log("load");
            //var deferred = this.own(...)[0]; // @1
            this._registerdPropertyGrids.forEach(function(element, index, array) {
                console.log('_registerdPropertyGrids[' + index + '] = ' + element.widgetName);

                var deferred = this.own(...)[0]; // @2
            }, this);
        }
    });
    if (!_instance) {
        var _instance = new SingletonClass();
    }
    return _instance;
});
我想它与单个类的实现有关


因此,我的实际问题是:为什么它说当我在“define”的依赖项列表中有dijit/Destroyable时,this.own没有定义?

您有
dijit/Destroyable
作为依赖项列出,但实际上您并没有使声明的构造函数从中扩展,因此,您自己的原型上没有
own

您需要的不是
declare(“…”,null,{
),而是
declare(可销毁,{
(其中
destroyable
正在替换
null

注:

  • 要声明的字符串参数已被弃用,因为它填充了全局命名空间,AMD不鼓励这样做
  • 我建议将
    destroyable
    重命名为
    destroyable
    。构造函数的常见约定是以大写字母开头

是否有可以找到dojo约定的链接/文档?我一直在搜索,但找不到任何内容。列出dojo 1.x的约定;列出用于dgrid 0.4、dstore、Intern和未来软件包的约定。