0

I want to set up a manager with a handler object that provides a specific function for each request. Why is only syntax a) working in other sample code I saw syntax b)

a)

 my.manager.requesthandler.create();

.

b)

my.manager.requesthandler [create]();   

.

// my manager-modul

(function(){

my.manager = (function(){


    var requesthandler = {


        create: function () {

            //do something
        }

    };

    return {

        requesthandler : requesthandler 
    };

})();

})();
2
  • 2
    if my.manager.requesthandler.create(); works then b should be my.manager.requesthandler["create"](); Commented May 1, 2013 at 14:48
  • @user1651640 Thank You so much, You are totally right! Commented May 1, 2013 at 14:51

1 Answer 1

1

my.manager.requesthandler.create

is equivalent to

my.manager.requesthandler["create"]

(notice the quotation marks)

what you wrote as b

my.manager.requesthandler[create]

means looking up a variable named create and getting

my.manager.requesthandler["whatever string create's value is"]

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

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.