Maknib Posted February 21, 2012 Share Posted February 21, 2012 Hi guys, i am taking the Javascript course from Learnable.com (sitepoint). we have come up to Objects in Javascript.. he has stated something like: var MyObject = { init: function(){ //do stuff }, something: function(){ //do something else } }; MyObject.init(); he has said that i need to put myObject.init(); on the bottom as the object hasn't been created yet if i try to call it from the top.. i'm gathering that this is similar to.. public class MyObject{ public void init(){ //do stuff } public void something(){ //do something else } } i'm wondering, because i'm starting to get used to working with classes and a Main class... can i have all my objects declared in another JS file, and use an include or an import in another "main" js file? purely for neatness? as i would like to have all funtions / objects in one file and the workings of the script in another. is this possible in Javascript? hope this makes sense thanks Quote Link to comment https://forums.phpfreaks.com/topic/257427-includes-and-objects/ Share on other sites More sharing options...
trq Posted February 21, 2012 Share Posted February 21, 2012 is this possible in Javascript? There isn't much that isn't these days. You can include javascript files into your pages using.... <script type="javascript" src="somescript.js"> So in your case you could have.... <script type="javascript" src="yourobjects.js"> <script type="javascript" src="yourcallingcode.js"> There are also numerous libraries around that will let you dynamically load js into other js files, but generally, these are overkill for most cases. Quote Link to comment https://forums.phpfreaks.com/topic/257427-includes-and-objects/#findComment-1319455 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.