Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.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对象嵌套回调_Javascript_Callback - Fatal编程技术网

javascript对象嵌套回调

javascript对象嵌套回调,javascript,callback,Javascript,Callback,我正在设计一个对象,如下所示。但是JavaScript不可嵌套调用。我感谢各位同事提出了这方面的想法。我共享原始代码 var preloading = {}; Object.defineProperties(preloading,{ show:{ enumarable:true, writable:false, value:function(value){ var $this = this;

我正在设计一个对象,如下所示。但是JavaScript不可嵌套调用。我感谢各位同事提出了这方面的想法。我共享原始代码

var preloading = {};
Object.defineProperties(preloading,{
    show:{
        enumarable:true,
        writable:false,
        value:function(value){
            var $this = this;
            jQuery($this._object).find('.text').eq(0).html($this.text).end().end()
                .velocity('stop').velocity('fadeIn',{
                    duration:500,
                    complete:function(){
                        console.log('preloading show');
                        if(value instanceof Function || typeof value === 'function'){
                            $this._start(value);
                        }
                    }
                });
        }
    },
    hide:{
        enumarable:true,
        writable:false,
        value:function(value){
            var $this = this;
            jQuery($this._object).velocity('stop').velocity('fadeOut',{
                duration:500,
                complete:function(){
                    console.log('preloading hide');
                    if(value instanceof Function || typeof value === 'function'){
                        $this._finish(value);
                    }
                }
            });
        }
    },
    _start:{
        enumerable:false,
        writable:false,
        value:function(value){
            var $this = this;
            value.call(undefined, $this);
        }
    },
    _finish:{
        enumerable:false,
        writable:false,
        value:function(value){
            var $this = this;
            value.call(undefined, $this)
        }
    },
    _object:{
        writable:true,
        value:'#preloader2',
        enumarable:false
    },
    object:{
        get:function(){
            return this._object;
        },
        set:function(value){
            this._object = value;
        }
    },
    _text:{
        writable:true,
        value:'yükleniyor..',
        enumerable:false
    },
    text:{
        get:function(){
            return this._text;
        },
        set:function(value){
            this._text = value;
        }
    }
});
然后我试着

preloading.show(function(preloading){preloading.hide()})
--第一次回调开始

//show callback starting
--第二次回调未启动


好主意吗?

您有不同的变量名-您的参数是
回调
,但您正在调用

您还拼错了
对象.defineProperties
预加载.defineProperties
)、
可枚举的(
可枚举的
)和
设置超时
设置超时

当然,您正在调用
preload.hide()
,而没有回调,因此它尝试在
未定义的
上调用

你会想读的。

试试这个

var preloading = {};
Object.defineProperties(preloading,{
    show:{
        enumerable:true,
        writable:false,
        value:function(callback){
            var $this = this;
            setTimeout(function(){
                console.log('show callback starting');
                callback.call(undefined, $this);
            },500)
        }
    },
    hide:{
      enumerable:true,
      writable:false,
      value:function(callback){
          var $this = this;
          setTimeout(function(){
              console.log('hide callback starting');
              callback.call(undefined, $this);
          },500)
      }
    }
});

您使用了
预加载而不是
对象。定义属性(..)
setTimeOut
而不是
setTimeOut
这可能是问题所在。

enumable
应该是
可枚举的
这没关系。我用手写的很快当然没关系,这就是为什么这是一个评论而不是答案:-)我编辑。但不起作用:)只是个问题,不是吗
Object.defineProperties(…