calmchess Posted October 29, 2012 Share Posted October 29, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270034-object-literals-nested-functions/ Share on other sites More sharing options...
kicken Posted October 29, 2012 Share Posted October 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270034-object-literals-nested-functions/#findComment-1388454 Share on other sites More sharing options...
calmchess Posted October 29, 2012 Author Share Posted October 29, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270034-object-literals-nested-functions/#findComment-1388455 Share on other sites More sharing options...
.josh Posted October 29, 2012 Share Posted October 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270034-object-literals-nested-functions/#findComment-1388456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.