Friday, February 26, 2010

Free domain for free hosting gofreeserve

hay guy's in this page I'll continue about Free domain for gofreeserve. Such as What I said just now on another page before if you can use free domain in gofreeserve such as co.cc , co.nr and without Advertising from them.. it's really free future for you.

Okay if you have not domains when you registered first, you can direct go to co.cc or co.nr for register free domain and than now I'll show you how to configuration your free domain with gofreeserve,

first, you have to Log in to you gofreeserve account.


Than Click -> Addon Domains -> type your domain name -> Add Domain




automatically gofreeserve will create folder in File manager, Let's Go to Online File Manager
click folder with name your domain -> than htdocs

upload your website file in htdocs folder
eg. xims.co.cc/htdocs

okay, don't forget when you register in co.cc .
you have to configuration also there, from first page go to Name server, than fill

Name Server 1 : ns1.gofreeserve.com
Name Server 2 : ns2.gofreeserve.com

Okay, that's all are you ready with your site?
don't forget to always visit Hosting and Domains info

I say thanks to blogger master id in 100master

Free Hosting gofreeserve

Hay guys, now time to sharing about free hosting from gofreeserve, Now I have finished review form there. and now it's time to share free hosting service form gofreeserve. Okay let's

Free Web Hosting Account Features :

- Account Control Panel
Their hosting platform uses the powerful vistapanel control panel. This fully featured control panel system allows you to control your account and provides a portal for managing all domain names and hosting with your account. Easily and effectively manage email, domains, databases, FTP, software installation and much more from one easy to use graphical interface.


- Website Builder
Building a website is now easier than ever, Their website building tool is a great value added feature that allows you to select a design template and build your entire website online within minutes. The user-friendly website builder is an ideal introduction for beginners to create and publish stunning websites very easily from the large collection of templates available without having to know HTML.


- Automatic Script Installer
The Fantastico Type Installer automates the installation of common web scripts such as CMS, forums, blogs and more. It's so easy to use that even novice web developers can install a new forum for their website with a few clicks of the mouse. A process which can take 15 minutes to an hour depending on your connection is reduced to a minute or two thanks to the powerful and easy to utilize script installer.


- MySQL Database Management
Their provide you with the tools to create and manage your databases. To administer MySQL databases you can use phpMyAdmin which is included within the control panel allowing you to carry out many different operations with MySQL to manage effectively. Also integrated is the slow MySQL query tool to pinpoint slow SQL code in MySQL, this information can help resolve performance problems to speed up your MySQL queries.


- Multi Domain Hosting
Create multiple domains / websites on the same account which gives you far more flexibility to utilize your web hosting space. With this feature you can host an additional number of domains and sub domains that are totally independent web sites all sharing the same control panel. You can also park additional domain names to your hosting account allowing you to access one web site with two different names.


wow... Very Wonderful, But Wait... I have more Information
Do you know how much you will get Storage ? 1000 MB for Free
Do you know how much you will get free bandwidth ? 40960 Mb for free
Do you know how much you will get free SQL space database ? 50 Mb for free +PHP Support

Do You want Info more ? Okay Let's Continue . .
it's about FREE DOMAIN , you will use free domain in your free account such as co.cc and co.nr Okay more describe about Free Domain for gofreeserve I will Describe Letter in Next Page about free domains for free hosting gofreeserve

Still Wait in Hosting And Domains info
I say thanks to blogger master ID in 100master

Seo List Free Directory PR3

Hello Guys,  Did you know what I want to share know?
Humm.. Bellow is List Free Directory For you These directory have PR3, okay Let's Go Submit your site Now

www.wilridge.com

www.uraputki.org

www.timbenderhats.com

www.thewindingsheet.com

www.talkers.ws

www.rukhnama.com

www.netnodder.com

www.nadrealizem

www.mzyon.net

www.linkspecialists.info

www.linkspecialist.info

www.linkspecial.info

www.linkspawn.info

www.linkspanner.info

www.linkspa.info

www.linksower.info

www.linksow.info

www.linksought.info

www.linksorters.info

www.inlivecaffe.com

www.free-directory.ws

www.business-resource.biz

www.shadowshow.net

Ha... are you happy now ? Okay give comment in ShoutMix Chat Box

SEO Submit Site To Search Engines

Hii guys, I got this article form Mater Shaun Anderson. now I want to share this article for you, Okay Let's Begin.

Firts. check your website or your blog in search Engine
How Do I Check If My Site Is In Google?
Just type your website address in the Google search box. If Google knows about your site, it will tell you. If your website doesn’t come up as a result, you need to submit your site to Google. Another way to check if a page is in either of the search engines is to lift a piece of unique text from the page, put it in a search “in quotes”.Your page should come up.

Second. if you not found your site
How Do You Submit A Site To Search Engines?

You do not need a SEO agency to submit your site to Google. You don’t pay to get into any of the big search engines. As I have said many times in the past, the best way to actually get into Google and the other top search engines is for the search engine spider to find your site through a link that is already on another website which Google already has in it’s index. A link from a blog, forum or other website. Any link will do as long as Google sees it as a link. For example, if you have a web design company, join a web design forum that allows you to put a link to your website in a signature. When it comes to links, think how relevant the page is your wanting the link from to your website. Many think relevant links are very important.

You could of course think about submitting your site to directories like Yahoo or (if you can stand to wait years if you are unlucky) DMOZ or asking other sites in your niche to link to you.

But if you are very lazy, you could just tell the search engines about your site. Not that I ever recommend this sort of thing:

 

    JavaScript Creating time delays

    Hey guys, Meet with me again, okay let's we continue with Java Script creating time delays
    There are two ways of creating time delays with JavaScript. The first is more simple and will simply wait for a specified amount of time before executing a function. The second does the same but will repeatedly execute the function.

    Note, most browsers have a minimum delay length of between 25 and 75 ms. If a shorter delay is specified, the actual delay will be the minimum delay length. Even with higher numbers, the delay is never perfect. Most browsers will take slightly longer than the time you ask for, typically just a few miliseconds error. Some may correct their errors over time with interval timers. Also note, setting many timers with short delays on one page will cause the browser to become slow and somewhat unresponsive. Three or four timers is usually the reliable limit.

    setTimeout

    The first method uses a window method called setTimeout(). The method waits for a specified number of milliseconds then executes the specified code. The code can either be a direct reference to a function, or it can be a string that will be evaluated as if it contained source code.

    window.setTimeout(referenceToFunction,timeInMilliseconds);

    window.setTimeout('runMoreCode()',timeInMilliseconds);
     
    Wherever possible, you should use a direct function reference as it is much more efficient. Using a string requires the browser to create a new script environment so it can process the script.

    If you create a timeout, the code after the call to setTimeout will continue to run as normal. After the specified delay, the timeout will start a new thread, and the code specified in the call to setTimeout will be run in the new thread, along side any code that is still running in the initial thread. Unlike with many more complex languages, JavaScript does not offer any way to control when those threads sleep, wake, or yield. The JavaScript engine handles all of that, and you must accept that your new thread could be executing at any time next to another thread. Many JavaScript engines will simply allow one thread to complete before allowing the other thread to start. The same applies to events, which run in their own threads, and can be triggered at any time.

    To pass variables to a timeout, you can use either format. To use a string, it is necessary to make sure the variables you want to pass can be represented in one of the primitive data types, and do not contain any characters that will break the string format (such as quotes). If possible, you should avoid this format, but this is an example, just in case you need to:

    window.setTimeout
    ('runMoreCode(\''+someString+'\','+someNumber+')',10);
     
    window.setTimeout('runMoreCode()',timeInMilliseconds);
     
    Wherever possible, you should use a direct function reference as it is much more efficient. Using a string requires the browser to create a new script environment so it can process the script.

    If you create a timeout, the code after the call to setTimeout will continue to run as normal. After the specified delay, the timeout will start a new thread, and the code specified in the call to setTimeout will be run in the new thread, along side any code that is still running in the initial thread. Unlike with many more complex languages, JavaScript does not offer any way to control when those threads sleep, wake, or yield. The JavaScript engine handles all of that, and you must accept that your new thread could be executing at any time next to another thread. Many JavaScript engines will simply allow one thread to complete before allowing the other thread to start. The same applies to events, which run in their own threads, and can be triggered at any time.

    To pass variables to a timeout, you can use either format. To use a string, it is necessary to make sure the variables you want to pass can be represented in one of the primitive data types, and do not contain any characters that will break the string format (such as quotes). If possible, you should avoid this format, but this is an example, just in case you need to:
      
    window.setTimeout
    ('runMoreCode(\''+someString+'\','+someNumber+')',10); 
     
    The direct function reference is much more easy, as you can pass variables as extra setTimeout method. In addition to being more easy, it is also able to accept any type of variable.Be careful with browsers that use the Mozilla Gecko engine (such as
    Firefox and Netscape 6+)as they will always pass an extra parameter to the function - the number of miliseconds error. This example uses an inline anonymous function, and is equivalent to using a direct function reference:

     
    window.setTimeout(function (a,b) {
      //do something with a and b
    },10,someString,someObject); 
    
    
    The variables that are passed to the function will be the values held by the variables at the time that the method was called. For example, assume you had a variable called myVar and it contained the number 5.
    You then called a timeout, passing it the variable myVar, and set it for a delay of 1 second. Immediately you change the value of  myVar to 7. When the timeout fires,it will run the function, and pass
    it the number 5, since that was the value myVar contained when you
    called the function.

    setInterval


    The setInterval method is identical in syntax to setTimeout(). The difference is that as well as firing after the specified delay, it will fire again after the same delay, and will continue to fire at the specified interval until it is cancelled.

    window.setInterval(function (a,b) {
      //do something with a and b
    },10,someString,someObject);

    Clearing timeouts and intervals


    You can cancel a timeout or interval by calling the relevant clearTimeout or clearInterval method, passing it a reference to the interval object. The code specified in the timer will not be run. In this example, an interval timer will be set to fire once every second (it will perform a useless task of incrementing a number, just as an example), and a timeout will be set to cancel the interval after 3.5 seconds:

    var myInterval = window.setInterval(function (a,b) {
      myNumber++;
    },1000);
    window.setTimeout(function (a,b) {
      clearInterval(myInterval);
    },3500);

    You can obtain the timeout object in the same way as shown here for the interval, and you can cancel it in the same way, using clearTimeout.

    Tuesday, February 23, 2010

    JavaScript Creating objects

    Any function in JavaScript can be used to create custom object classes, simply by calling it using the keyword new. When called in this way, the special variable this inside the function references the new object that is being constructed (it normally refers to the 'current' object, which is usually window, except inside methods). The function should not return a value. The following function can be used as demonstrated to create an object of class myobject:

    function myobject() {
      this.containedValue = 0;
      this.othercontainedValue = 0;
      this.anothercontainedValue = 0;
    }
    
    var mything = new myobject();
     
    And there you go, mything is now an instance of class myobject. It will have the following properties, all of which will be 0: 

    -  mything.containedValue 
    -  mything.othercontainedValue 
    -  mything.anothercontainedValue

    You could also now write this:

    myobject.prototype.newContainedValue = someValue;
     
    This will cause all instances of class myobject will have the property newContainedValue with value someValue.
    Use the instanceof operator to find out if your object is an instance of a given object class:

    
    
    if( myvar instanceof Array ) { ... }
    if( myvar instanceof myobject ) { ... }
     

    Creating an object with methods

    Now I will give you an example showing you how to create methods for your objects. As an example, I will create a circle as my object. The methods will be
    nameOfCircle.retArea()
    Returns the area of the circle (pi r2)
    nameOfCircle.retCirc()
    Returns the circumference of the circle (2 pi r)
    nameOfCircle.mvBy(xDis,yDis)
    Moves the circle by xDis in the x direction and yDis in the y direction
    The following lines point the methods to functions that the object will use as the methods: 

    -  this.retArea = getTheArea; 
    -  this.mvBy = mvCclBy; 
    -  this.retCirc = function () { ... };

    The third of these defines the method using an anonymous function in one line, and does not work in some early Netscape 4 releases. Note, it has a semicolon after the '}', and is one of the few places where this is correct practice.


    function mycircle(x,y,r) {
      this.xcoord = x;
      this.ycoord = y;
      this.radius = r;
      this.retArea = getTheArea;
      //This next line uses an alternative syntax
      this.retCirc = function () 
    { return ( Math.PI * this.radius * 2 ); };
      this.mvBy = mvCclBy;
    }
    function getTheArea() {
      return ( Math.PI * this.radius * this.radius );
    }
    function mvCclBy(xDis,yDis) {
      this.xcoord += xDis;
      this.ycoord += yDis;
    }
    
    /*
    create a mycircle called testcircle where testcircle.xcoord is 3
    and testcircle.ycoord is 4 and testcircle.radius is 5
    */
    var testcircle = new mycircle(3,4,5);
    /*
    use the mvBy method to displace the centre of testcircle.
    move it by 2 in the x direction and 3 in the y direction
    */
    testcircle.mvBy(2,3);
    //testcircle.xcoord is now 5 and testcircle.ycoord is now 7
    
    window.alert( 'The area of the circle is ' + testcircle.retArea() 
    );
    window.alert( 'The circumference is ' + testcircle.retCirc() );
     

    The special 'toString' method

    All objects have the 'toString' method, even if you do not define it yourself. The method returns a string representation of the object, and is automatically called whenever a string representation of an object is required, such as when you use alert(myObject);
    In most browsers, this returns '[object Object]', although some more useful browsers return a string like this:

    '{property1:value1,property2:value2,method1:function () 
    { ... },etc.}'

    However, for your own objects, you may wish to provide a special string that may provide more useful information. To do this, simply define the 'toString' method:

    this.toString = function () {
      return 'Circle object; xcoord: ' + this.xcoord + ', ycoord: '+
        this.ycoord + ', radius: ' + this.radius;
    };
     
     

    Advanced object techniques


    These deal with concepts that are rarely used in JavaScripting. JavaScript is 
    a more powerful programming language than most people make use of, 
    but that is because in normal scripting, these powerful features are not really 
    necessary. If you are just learning
     
    Some of these techniques may not work in older browsers like early Netscape 
    4 releases.

    Adding extra properties/methods using prototype


    Take the mycircle example from the top of this section (creating new objects). We have already created an instance of the mycircle class called 'testcircle'. And we can also assume that we have created a few other mycircles. Now, let us assume that we want to add another property to each circle. For example, we want each circle to have a 'texture' property. We could use this:

    testcircle.texture = 'smooth';
     
    And we could do this for each individual mycircle. But since we want to do this for all of them, it would be much more easy to give all instances the property at the same time. So we can use the 'prototype' property of the class constructor:

    mycircle.prototype.texture = 'smooth';
     
    Immediately, all of the mycircles that we have created will now 
    inherit the new property: 
     
    alert(testcircle.texture);
    //alerts 'smooth'
     
    We can add new methods the same way:
     
    mycircle.prototype.setArea = function (oArea) {
      this.radius = Math.sqrt( oArea / Math.PI );
    };
    mycircle.setArea(5);  
     
    This is most useful with instrinsic (fundamental inbuilt) objects. For example,
    the regular expression construct /a[0-9]b/g is shorthand for new  
    RegExp('a[0-9]b','g'); and in fact the same is true for all intrinsic 
    object classes, such as String, Number and Boolean. So if, for example, 
    we wanted to create a new method on all strings called 'reverse' that 
    returned their contents in reverse order, we could do this: 
     
    String.prototype.reverse = function() {
      for( var oStr = '', x = this.length - 1, oTmp; 
        oTmp = this.charAt(x); x-- ) {
        oStr += oTmp;
      }
      return oStr;
    }; 
    
    
    The use of prototype could have been applied to create all of the methods of 
    the mycircle object, not just new ones. This gives a mixed response to 
    performance. It will not have to store individual copies of the methods for each 
    instance of the object, so it may require less memory, but it will require the 
    browser to search the current and parent scopes to find the methods. This may 
    cause a marginal delay. Generally, you should use what is appropriate for 
    your code, and not base this decision on performance (unless you are dealing 
    with a very specific controlled environment):
     
    function mycircle(x,y,r) {
      this.xcoord = x;
      this.ycoord = y;
      this.radius = r;
    }
    mycircle.prototype.retArea = function () {
      return ( Math.PI * this.radius * this.radius );
    };
    mycircle.prototype.retCirc = function () {
      return ( Math.PI * this.radius * 2 );
    };
    mycircle.prototype.mvBy = function (xDis,yDis) {
      this.xcoord += xDis;
      this.ycoord += yDis;
    }; 
    In some cases, it may be desirable to work out if a property on an object is 
    attached to the object instance itself, or somewhere in its prototype chain. 
    In JavaScript, all objects have a method called hasOwnProperty
    that returns true if the given property is attached to the individual object 
    instance. Of course, it is also possible to check if the object's constructor 
    also has the same property with the same value as the object instance itself, 
    but that can give the wrong result if separate properties exists with the same 
    value on both the object instance and the prototype chain. 
    The hasOwnProperty method accepts a single parameter; the name of the 
    property as a string.
     
    function myclass() {
      this.propertytwo = 2;
      this.propertythree = 3;
    }
    myclass.prototype.propertyone = 1;
    myclass.prototype.propertytwo = 2;
    
    var myinstance = new myclass();
    myinstance.propertyfour = 4;
    
    alert(myinstance.hasOwnProperty('propertyone'));
    //alerts false
    
    alert(myinstance.hasOwnProperty('propertytwo'));
    //alerts true
    
    alert(myinstance.hasOwnProperty('propertythree'));
    //alerts true
    
    alert(myinstance.hasOwnProperty('propertyfour'));
    //alerts true
    
    alert(myinstance.hasOwnProperty('propertyfive'));
    //alerts false 

    Public and private properties

    This is a concept that is almost never used in JavaScript, and there is a good reason. It simply is not necessary. Even complicated scripts are almost never complex enough to require this level of control. However, many programmers familiar with other programming languages (such as Java or C++) often desire this behavior in JavaScript simply because it is a concept they are familiar with. This sort of concept is only really useful when putting together large projects from multiple pieces of code.
    Say for example that I am producing a public functions library. A set of constructors and methods that people can include in their own projects (something that Java programmers use all of the time). Say for example that the mycircle constructor is included in it, so that you can create your own mycircles. Now say for example you try this:

    var aCircle = new mycircle(5,6,'about 3mm'); 

    That will work now (it's not a valid measurement, but my constructor will not argue), but later on when you try to use the methods that my class provides, it will fail. So I can check what you have provided, and make sure it is a valid number, and use a default value if it is not. But then you can say something like this:
    aCircle.radius = 'some text';
     
    Again, it would break (of course, it is your own fault, but in more complicated 
    applications, it would be possible to make a mistake where this causes 
    a real problem). So what I want to do is to not allow you to modify that 
    property directly, and only allow you to change it using a method that I control:
    
    
    this.setRadius = function (oRad) {
      if( typeof(oRad) == 'number' && oRad >= 0 ) {
        this.radius = oRad;
      } else {
        this.radius = 0;
      }
    };
    
    
    An alternative situation where this can be important is if I am storing the information in one set of properties. I then upgrade my libraries, maybe adding some extra functionality. But in order to do so, I have to change the properties that I am using. If your script was relying on them existing in a specific format, and I have now changed that format, your script would fail. If I could protect those properties, and force you to use only methods, then I could do whatever I needed with the properties, and as long as I then change the methods to use the new properties, your script would keep working, and you would not even need to know what I had changed or why. That way, we could each manage our own project, and not waste each other's time.

    It would also help avoid possible conflicts between undisclosed properties, and your own scripting. For example, if you decide to temporarily assign a property to an object, but you were unaware that internally, my object constructor already used that property name, you would overwrite my object's property, and cause problems with the object.

    This is what private properties are for. They do not allow scripts that use the contructor to use or modify the properties directly. They only allow the methods of the object itself to use and modify them. Unlike many other languages, JavaScript does not declare each variable type as 'public' or 'private'. It all depends on how you create them.

    Saying 'this.propertyname' as I did above will create a public property. Any script can create an object then use and modify its properties directly. Using 'var' to define a variable in the constructor will create a private property. Note that unlike public properties, the private properties are then accessed, including from within methods, without the 'this.' prefix - just like a normal variable. This makes heavy use of JavaScript's scope functionality. Private variables can only be accessed from methods that are declared inline, and not externally referenced or created using the prototype construct. Methods of this kind are also known as privileged methods. An example of its use might be: this.mymethod = function () { alert( propertyname ); };

    function myob() {
      this.property1 = 'value1'; //this creates a public property
      var property2 = 'value2';  //this creates a private property
      this.method1 = function () { alert( property2 ); };
    }
    var oneOb = new myob();
    alert(oneOb.property1); //alerts 'value1'
    alert(oneOb.property2); //alerts undefined (private property)
    oneOb.method1();        //alerts 'value2'
     
    Similarly, you can also create private methods. These are simply a function that 
    you create inside the constructor function. This may look confusing, but it works. 
    The private function can only be called by the constructor itself, or by methods 
    that are defined inline. Private methods can be used as public methods, 
    if they are assigned to a public method constructor, and accessed using 
    the public method constructor (as with 'method2' below). 
     
    function myob() {
      function cantBeSeen() {
        alert(secretValue);
      }
      var secretValue = '';
      this.method1 = function () {
        secretValue = 'no surprises';
        cantBeSeen();
      };
      this.method2 = cantBeSeen;
    }
    var oneOb = new myob();
    oneOb.method1(); //alerts 'no surprises'
    oneOb.method2(); //alerts 'no surprises' 
    
    

    Sub-classes and class inheritance

    This is also hardly ever used in JavaScript, despite its popularity in other languages. Take this as an example. I want to make a new type of object, that will store the data to represent a sphere (a ball - in case you don't know). Since a sphere is just a three dimensional circle, I would probably want to include all the methods I created earlier for the circle object; retArea to get the cross-section area, retCirc to get the circumference, mvBy to move it by a certain amount. Aditionally, I would probably want retVol to get the volume, and retSurf to get the surface area. I would also need to provide a z coordinate when creating the object, and again when calling the mvBy property.

    So, I want to create a new type of object, based on the mycircle, but with a few aditions and modifications. I will call this new type of object a mysphere. Now, I could just rewrite all the code I already wrote for the mycircle and change the bits I need. But in a real-world application, this might be a lot of wasteful duplication, for only one or two modifications. So what I want to do is make the mysphere inherit all the properties and methods of the mycircle, then overwrite only the ones I want.

    This effectively makes mysphere a sub-class of mycircle, and making the mysphere class constructor inherit from the mycircle class constructor is as simple as this:

    function mysphere(x,y,z,r) { ... constructor code ... }
    mysphere.prototype = new mycircle();
     
    In case you are wondering, the way it works is to actually create a mycircle, 
    then assign that to the mysphere constructor prototype. As a result, 
    the mysphere constructor has the mycircle object added to its prototype 
    chain. What this means is that each time a mysphere is created, it will inherit 
    the properties and methods of  the mycircle object. It can then override any 
    of these properties using its own prototype, or with properties and methods 
    created within its own constructor. If any of these properties are subsequently 
    removed (using the 'delete' keyword), the inherited ones will become available 
    again. That also means that if the mycircle prototype is changed 
    (properties are added or deleted, etc.), these changes are replicated down 
    the chain, so the mysphere also inherits these changes. 
     
    Note that the prototype chain is established for each object as the object is created. Once an object has been created, its prototype chain cannot be changed (though new properties and methods can still be added to its parent classes, and those changes will be reflected in the object). Changes to its prototype chain will have no effect; it will still see the old prototype chain. The new chain will only be used for new instances of that class. This is also the case for the assignment of a new mycircle to the prototype of mysphere (which, as stated, creates a new instance of the mycircle class); any subsequent changes to the prototype chain of the mycircle class will not be reflected in the mysphere class. For this reason, it is very important to ensure that the prototype chain is built in the correct order, with class constructors and their prototypes set up before any child class is made to inherit from them. Properties and methods can still be added to any class or parent class at any time after their own prototype chain has been set up.

    The line that makes mysphere inherit from mycircle sounds simple enough. And at least, it would be, but you will remember that mycircle expected me to pass it some parameters that it would then use. Then I call my new constructor, and these parameters will not automatically be passed to the mycircle constructor function. I need to do this myself for each mysphere that I want to create. But since I am not passing these parameters when assigning the mycircle object to the mysphere prototype, I also need to ensure that the mycircle contructor stops before attempting to create its own properties. Instead of defining the public properties immediately, I will define them using a method (that I have decided to call getready), and if the required parameters have been passed (arguments.length), I will immediately call the method.

    If the parameters are present, the mycircle constructor keeps working, and no-one needs to know that anything was changed at all. To make things easier later on, I will take all of the methods out of the constructor, and add them later using the prototype. That way, the mycircle prototype methods will always be available without me needing to create a new mycircle. Unfortunately, this also means that public and private properties are very hard (or impossible) to use. It's a trade off - one functionality for another.
     
    function mycircle(x,y,r) {
      if( arguments.length ) { this.getready(x,y,r); }
    }
    mycircle.prototype.getready = function (a,b,c) {
      this.xcoord = a;
      this.ycoord = b;
      this.radius = c;
    };
    mycircle.prototype.retArea = function () {
      return ( Math.PI * this.radius * this.radius );
    };
    mycircle.prototype.retCirc = function () {
      return ( Math.PI * this.radius * 2 );
    };
    mycircle.prototype.mvBy = function (xDis,yDis) {
      this.xcoord += xDis; this.ycoord += yDis;
    }; 
    
    
    
    
    Now, back to the mysphere constructor. I have already said how to make it inherit, but it still needs to run the mycircle.getready method to initialise the properties. To do this, we will need to reference the parent class prototype, and run the method ourselves. This also ensures that even if each parent class uses the same method name (getready), the correct one is always referenced. Since we can almost never be sure how many sub-classes we will need, it is useful to do it this way, and simply use the same method name for each, knowing that we will not have problems with name conflicts.

    When running the method, we need to tell JavaScript that even though we are referencing a method for a different prototype, we want to run it as if it were a method of the object we are creating (to make sure that any properties it creates are added to the object we are creating). This could be done using the 'call' method or 'apply' method, but unfortunately, Internet Explorer 5 does not understand these, so I will assign it to a temporary property of the new object, and run it from there.

    To reference the method from the parent class prototype, it would be possible to use the constructor's prototype chain to locate it (the property that references the constructor will, at this point, refer to the parent class - more on that later):

    this.constructor.getready

    However, that will only work for one level of inheritance, due to the way it is run as a method of the current object for all child classes. As a result, it is best to reference it by name, which will work no matter how many levels of class inheritance are used:

    mycircle.prototype.getready
     
    Note that when assigning the mycircle object to the mysphere prototype, 
    it also overwrites the mysphere prototype constructor  property. This is 
    not a major problem, but some scripts use it, so we will put 
    the reference back where we want it:
     
    function mysphere(x,y,z,r) {
      if( arguments.length ) { this.getready(x,y,z,r); }
    }
    //inherit from the mycircle prototype
    mysphere.prototype = new mycircle();
    //put the correct constructor reference back (not essential)
    mysphere.prototype.constructor = mysphere;
    
    mysphere.prototype.getready = function (a,b,c,d) {
      //reference the getready method from the parent class
      this.tempReady = mycircle.prototype.getready;
      //and run it as if it were part of this object
      this.tempReady(a,b,d);
      //now that all required properties have been inherited
      //from the parent class, define extra ones from this class
      this.zcoord = c;
    }
    mysphere.prototype.mvBy = function (xDis,yDis,zDis) {
      //override the existing method
      this.xcoord += xDis;
      this.ycoord += yDis;
      this.zcoord += zDis;
    };
    mysphere.prototype.retVol = function () {
      return ( 4 / 3 ) * Math.PI * Math.pow( this.radius, 3 );
    };
    mysphere.prototype.retSurf = function () {
      return 4 * Math.PI * this.radius * this.radius;
    }; 
     
    And finally, to use it:
     
    var testsphere = new mysphere(3,4,5,6);
    
    alert( 'The cross-section area is ' + testsphere.retArea() );
    alert( 'The circumference is ' + testsphere.retCirc() );
    alert( 'The volume is ' + testsphere.retVol() );
    alert( 'The surface area is ' + testsphere.retSurf() ); 
     
     
    There is no limit to how many sub-classes can inherit from a class,
    and there is also no limit to how many levels of sub-classes can 
    be created. As an example, I will create a ball class that will 
    inherit from the mysphere class: 
    
    
    function ball(x,y,z,r,m) {
      if( arguments.length ) { this.getready(x,y,z,r,m); }
    }
    ball.prototype = new mysphere();
    ball.prototype.constructor = ball;
    
    ball.prototype.getready = function (a,b,c,d,e) {
      this.tempReady = mysphere.prototype.getready;
      this.tempReady(a,b,c,d);
      this.mass = e;
    }
    ball.prototype.retDensity = function () {
      return this.mass / this.retVol();
    }; 
     
     
     
    The instanceof operator returns true when testing an object against any class 
    in its prototype chain, so it would say that an instance of the ball class was 
    also an instance of the mysphere class, and also the  mycircle class. 
    
    
    
    


     
    

    Java Writing functions


    General syntax

    Functions group together script code; control structures, operations, method calls, etc. in the same way as a normal script. These functions can then be called when needed, and the code contained within them will be run. This makes it very easy to reuse code without having to repeat it within your script.

    Functions are defined using one of these constructs:
    Normal function construct

    function nameOfFunction(listOfVariableNames) {
      function code should be written here
    }
    Anonymous function, assigned to a variable
    Using this syntax for object methods in early Netscape 4 versions will cause problems with the 'this' keyword due to bugs. 

    nameOfFunction = function (listOfVariableNames) {
      function code should be written here
    };
     
    Normal function construct, assigned to a variable
     
    nameOfFunction = function anotherNameForTheFunction
    (listOfVariableNames)
     {function code should be written here
    };

    Note : that in this particular case, because the function is being assigned, and not defined normally, the name anotherNameForTheFunction can be used by the code inside the function to refer to the function itself, but the code outside the function cannot see it at all (note that some browsers, mainly Internet Explorer, do not implement this correctly, so you should not rely on it - it is better to use arguments.callee as shown below).

    The Function class constructor

    functionName = new Function
    ("function code should be written here");
     
    This construct evaluates the code as a string, and is much slower than assigning anonymous functions. It should only be used in places where it is actually needed.

    The Function class constructor with parameters

    functionName = new Function
    ("varName","varName2","etc.","function code");

    Functions are called using one of these: 

    - nameOfFunction(listOfVariables); 
    - window.nameOfFunction(listOfVariables); 
    - object.onEventName = nameOfFunction;

    When created using the normal function construct, the definition does not have to appear at the start of the script (though it is usually best to do so for the sake of clarity). It can even be defined after the the code that calls it. In most cases, no matter where you choose to define your function, the JavaScript engine will create the function at the start of the current scope.

    Note : that you should never create a function using the normal function construct inside an 'if' statement (or any equivalent control structure):

    if( someCondition ) {
      function functionName() {
        ...this will not work in most browsers...
      }
    }

    This is permitted by Mozilla's JavaScript 1.5, but this conflicts with ECMAScript 3, the core language used by JavaScript 1.5. As a result, Mozilla based browsers allow it, and most others do not (they will always evaluate the function, even if the condition evaluates to false). It is best not to rely on either behaviour, and do not try to declare functions in this way. Declaring functions inside these statements is possible in all current browsers using assigned anonymous functions, and this is the correct way to achieve the desired effect:

    var functionName;
    if( someCondition ) {
      functionName = function () {
        ...
      };
    }



    Using the return statement

    The return statement causes a function to stop executing at that point. The code that called the function will still continue to execute.

    function doWhatever() {
      var apod = Math.pow(3,7);
      return;
      //the following code will not be executed,
      //no matter what
      apod *= 34;
      if( 700 * 3 <= apod ) {
        return;
        //return on its own is more usually
        //used as part of a conditional
      } else {
        window.alert('The script has made a mistake');
      }
    }

    The following is an example of using the return statement to return a variable from a function:

    function appendComment(passvar) {
      //in this case, I have passed a string variable and I return
      //a string variable. I could return any variable type I want.
      passvar += ' without your help';
      return passvar;
    }
    
    var myString = appendComment('I did it');
    //myString is now 'I did it without your help'
      
    Note that if you need your code to work in older browsers, it is important to make sure that if the return statement is used to return a value, you must ensure that in all cases, the function returns a value, or some Netscape 4 versions will produce errors.

    Take, for example, the action of fading. I want to write the same thing repeatedly, slowly fading from one colour to another. Rather than having to calculate this manually, I want to run some script that calculates the fade for me. The script will run nicely as part of a function, where the function returns the next colour at each step, which I can then use. This is useful, because I can then use the same function to produce a variation of the same effect later on, based on different parameters.

    function fadeColour( fromcol, tocol, fadePortion ) {
      //in the format fadeColour( 'ff0098', 'fe0934', 0.23 )
      var oF = [], oT = [], oP = [];
      var oH = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'];
      //get the red, green and blue substrings ...
      for( var x = 0; x < 3; x++ ) {
        //... and convert them from hex into decimal ...
        oF[x] = eval( '0x' + fromcol.substring( 2 * x, ( 2 * x ) + 2 ) );
        oT[x] = eval( '0x' + tocol.substring( 2 * x, ( 2 * x ) + 2 ) );
        //... add on the required portion of difference between the two ...
        oP[x] = Math.round( oF[x] + ( ( oT[x] - oF[x] ) * fadePortion ) );
        //... and convert it back into hex ...
        oP[x] = oH[ ( oP[x] - ( oP[x] % 16 ) ) / 16 ] + oH[ oP[x] % 16 ];
      }
      //... and put them back together again as a colour string
      return '#' + oP.join('');
    }
    
    for( var y = 0; y < 10; y++ ) {
      //in 10 steps, fade the colour - also see the section on writing with script
      document.write( '<span style="color:' + fadeColour( 'd2cbff', '000099', y / 9 ) +
      ';">Fade!<\/span> ' );
    }
    
    for( var y = 0; y < 12; y++ ) {
      //in 12 steps, fade the colour
      document.write( '<span style="color:' + fadeColour( 'ff0000', '000000', y / 11 ) +
      ';">Fade!<\/span> ' );
    }
    Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade!
    Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade! Fade!

    Warning, if you are returning a value from a function, do not call the function directly from the <a href= method to activate it, or many browsers will (correctly) create a new page containing the returned value as the page content. You can still use return; on its own. You can only return values if you call the function script from another piece of script (like another function). 

    If you need to call the function using the <a href= method, use the void operator.
    Note, returning false for many events will cancel the action. As an example, if a user submits a form, returning false will cause the form not to be submitted. The exception is onmouseover, where returning true will stop the mouseover from having any effect (such as with a link, where returning true will stop the link url from being displayed in the status bar).


    Variable scope
    Variable scope is one of the very useful features of languages like JavaScript, so even though it may seem a little complicated, it is worth taking the time to learn how it works.

    In a basic script, there may be any number of variables and functions. Take the following example:

    var a = 1, b = 2, c = 3;
    function sample() {
      var d;
      a = 7;
    }
    sample();
    alert(a);
     
    The variables a, b and c are not inside any function when they are declared, so they are in a scope called the global scope. They are available anywhere. Code anywhere else in the script, including inside the sample function, has access to them. The sample function is also global, since it is not inside any other functions. If any other piece of code changes the contents of those variables, then every other part of the code now sees the new contents. As a result, the alert here will show '7', since the value held by the global variable is changed when the function is run.

    Variable d is defined inside the sample function, so it is not global. It is in the local scope of the function. What that means is that only the code inside the function can see it. Code outside the function does not even know it exists. This happens with any function. They have the ability to create their own scopes, and their own local variables, without them interfering with variables located in the global scope. Variable names written in the brackets of the function definition are also created as variables in the local scope (and the same applies to the arguments collection):

    function sample(myvar) {
      //myvar is now a variable in the local scope
      alert(myvar);
    }
    sample('hello');
    
    
    Now try this modification to the earlier code:
     
    var a = 1, b = 2, c = 3;
    function sample() {
      var a, d;
      a = 7;
    }
    sample();
    alert(a); 
     
    Here, the variable a is redefined inside the function. 
    Because it is declared using the var keyword, it becomes a local 
    instance of a variable. Even though it shares the same name 
    as a global variable,the two are completely independent. 
    The changes made to that variable inside the function only affect
    the local variable, not the global one.As a result, 
    the alert will show '1', and not '7'.
     
    Now imagine that the code inside the function wants to reference 
    the global variable 'a' instead of the local one.The global scope 
    is special. In JavaScript, the global scope can be referenced 
    using the name 'window'. The code inside the function can 
    use window.a to reference the global 'a' variable.Incidentally,
    this is why methods like alert can be called using either alert 
    or window.alert, since these methods are globally available
    (unless they are overwritten in the current scope, of course). 

    Nested functions

    It is possible to create functions inside other functions. Simply declare another function inside the code of an existing function:
    var a = 1, b = 2, c = 3;
    function sample() {
      var a, d, e;
      function anothersample() {
        var e, f;
      }
      anothersample();
    }
    sample();


    In that example, the anothersample function only exists inside the sample function, and it can only be called by the code inside the sample function. Code outside that function does not even know it exists. The scopes are also nested, so the code inside the anothersample function has access to b and c from the global scope, a and d from the sample scope, and then e and f from its own local scope. It can also use window.a to reference the variable a from the global scope.

    Of course, if you assign a reference to the nested function to a global variable, then the function can be accessed globally through that variable. There is not much point in doing that here, but it becomes very useful when creating object methods (these will be covered in detail in a later chapter).

    Scopes have memory

    Scopes are actually very clever, since they persist over time. Imagine that the code inside a function creates a local variable. It also creates an event handler function that will be triggered when the user clicks a link:

    function sample() {
      var a = 20;
      document.links[0].onclick = function () {
        alert(a);
      };
    }
    sample();

    The action that calls the event handler (inner) function happens much later, a long time after the script that created it has finished running. However, the variable 'a' has survived, so the alert will display the number 20.


    Using scope to prevent conflicts


    Imagine that you are running a script that uses many global variable and function names. You want to put another script on the same page, but there is a chance that the two scripts will use the same variable names as each other, and may conflict. It is easy to workaround this problem by putting the code from each script inside a function, and running the function. That way, the local scope provided by the function will protect the variables overwriting each other in the global scope. Note that when doing this, it is very important that you remember to declare your variables properly.

    The easy way to do this without creating a global function is to create an anonymous function, and enclosing it in parenthesis (internally, the engine will then replace that entire construct with the function reference). You can then use the open-close parenthesis to run it immediately. This construct may look a little odd, but it works:

    (function () {
      //Put your script code in here
    })();