0

I'm designing an object as follows. But JavaScript does not nested callable. I thank colleagues an idea about it. I share the original code.

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;
        }
    }
});

then i try

preloading.show(function(preloading){preloading.hide()})

--first callback starting

//show callback starting

--second callback not starting

an idea?

Haydar C.
  • 742
  • 12
  • 24

2 Answers2

2

You've got different variable names - your parameter is callback, but you're calling value.

Also you've misspelled Object.defineProperties (preloading.defineProperties), enumerable (enumarable) and setTimeout(setTimeOut).

And of course you're calling preloading.hide() without a callback, so it tries to invoke .call on undefined which throws as well.

You'll want to read How can I debug my JavaScript code?.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
0

Try this out

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)
      }
    }
});

You used preloading.defineProperties(....); instead of Object.defineProperties(....); and setTimeOut instead of setTimeout that might be the problem.

domino_katrino
  • 356
  • 3
  • 19