Jump to content

Recommended Posts

If I nest a function inside another function within an object literal do I need to write the nested function like.

 

myFunc:function (){
myOtherFunc: function(){

}
}

 

or is it

 

myFunc:function (){
myOtherFunc=function(){

}
}

 

 

I'm trying to write Ajax stuff into an Object Literal

 

I also am curious about when the ajax object calls the on ready function I'm trying to write that function with a colon also.

 

Am I way off my mark or will what I'm trying to to work?

Link to comment
https://forums.phpfreaks.com/topic/270034-object-literals-nested-functions/
Share on other sites

The proper way (one of a few anyway) to define a function within a function that is in an object literal would be like this:

var myObject = {
   myFunc:function (){
      var myOtherFunc=function(){
      };
   }
};

 

I'm not sure if that is what you're looking for though.  It's hard to tell from your partial code samples and text what exactly it is you're trying to accomplish.

 

no that answers my question good enough for now. I am building a site in HTML 5 using a kindle fire because I'm in a hospital that doesn't allow laptops or the internet I'm currently on an outing to the library see and since I can't figure out how to test a local file in my kindle's browser I'm just writing sudo code anyway that reminds me I need to look up how to view a local file on a kindle. Thanks for your time and help. I'm currently building a forum using HTML/HTML5 javascript and aceessing the middleware with ajax

An alternative way would be like

 


var someObject = {
 myFunc : {
   myOtherFunc : function() {
     console.log('call from myOtherFunc');
   }
 }
};

 

Then you can do like

 

someObject.myFunc.myOtherFunc()

 

But as kicken mentioned, it kinda depends on what you are going for, how the rest of your stuff is structured.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.