views:

63

answers:

3

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

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

d.s();
cletus
+3  A: 

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
Kevin Montrose
+2  A: 

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

var d = function() {
  return {
    s: function() {
      alert('cool');
    }
  };
}();
d.s();  // invokes the function s
stefpet
thanks..thats it
Luke101