Thursday, June 9, 2011

JavaScript File Management





FileManager is small JavaScript file which manages JavaScript files as Java manages its files. It consists three methods

  1. Package: Package is same as Java package and it is first method which should get added in file.It require one argument which is relative path of the current JavaScript file ( excluding file name). For example there is a file inside "javascript->com->test->Home.js" then argument would be "com.test".    In the current file it would be like fm.Package("com.test");
  2. Import: Import is same as Java import and it can be added any number of times. It takes only one argument which is relative path of other file (including file name without extension) you want to import. For example if you want to add a file whose path is "javascript->com->test->HomeBaseClass.js" then argument would be "com.test.HomeBaseClass". This way you can import any number of files. In the current file it would be like fm.Import("com.test.HomeBaseClass"). Note: Importing same file multiple time is not a problem.
  3. Class: Class is little bit different from Java class as it has no functionality for as Java implements. It require at least one argument and at most two arguments. First arguments should be class name and second argument can be base class of current class. For example if file name is Test.js then current file would be like fm.Class("Home") or fm.Class("Test", "com.test.HomeBaseClass") where HomeBaseClass is base class of Test class inside "javascript->com->abc->base" folder.
Above are three method which can be used for JavaScript files management. If we put them together file would be like
fm.Package("com.test");
 
fm.Import("com.test.HomeBaseClass");
fm.Import("com.test2.Class2");
fm.Class("Home"); or fm.Class("Home", "com.test.HomeBaseClass");

Now you are ready to write your JavaScript file. Next step would be creating class
com.test.Test = function( importedClasses, baseClassObject ){

};
   In above code first argument is object of imported classes which can be used to create instance of imported class eg. var homebaseClass2 = new importedClasses. Class2();. You can also create instance as var class2 = new com.test.Class2(); and
   second argument is instance of base class which can be used to call base call functions;
   
    Next important step is constructor function which is optional this the first method get called when we create a object instance. in above case it would be this.Home = function(){};
   a after doing this class would be look like as
   com.test.Test = function( importedClasses, baseClassObject ){
      

       this.Test = function(){
           
      
};

  };

No comments:

Post a Comment