2

I am trying to call a function within a function. Here is the code

var d = function() {
    s: function() {
        alert('cool');
    }
} ();
d.s();

This does not work. What am I doing wrong

3 Answers 3

4

Erm... it looks like maybe you're trying to define an Object with a function?

In that case,

var d = {
  s: function(){
    alert('cool');
  }
};
d.s();  //Invokes the function s
Sign up to request clarification or add additional context in comments.

Comments

3

Here is another approach using the so-called module pattern:

var d = function() {
  return {
    s: function() {
      alert('cool');
    }
  };
}();
d.s();  // invokes the function s

Comments

1
var d = {
  s: function() {
    alert('cool');
  }
};

d.s();

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.