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?

7
  • 1
    enumarable should be enumerable Commented Dec 1, 2015 at 13:31
  • it does not matter. I wrote by hand quickly Commented Dec 1, 2015 at 13:33
  • 1
    Of course it does not matter, that's why this is a comment not an answer :-) Commented Dec 1, 2015 at 13:33
  • i edited. But not working :) Commented Dec 1, 2015 at 13:36
  • Just a question, isn't it Object.defineProperties(...? Commented Dec 1, 2015 at 13:42

2 Answers 2

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?.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.