String.prototype : prototype : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » prototype »

 

String.prototype









Syntax








String.prototype.property
    String.prototype.method



The prototype property adds properties or methods to a core JavaScript object.












<html>
    <script language="JavaScript1.1">
    <!--
    function myVerify(){
      if(this.type != "Name"){
        return false;
      }else{
        return true;
      }
    }
    String.prototype.type = null;
    String.prototype.verify = myVerify;

    var myString1 = new String("This is a test");
    var myString2 = new String("This is a name");

    myString1.type = "Name";
    myString2.type = "Title";

    if(myString1.verify()){
      document.write(myString1 + " has a valid type of " + myString1.type);
    }else{
      document.write(myString1 + " has an invalid type of " + myString1.type);
    }
    document.write('<br>');

    if(myString2.verify()){
      document.write(myString2 + " has a valid type of " + myString2.type);
    }else{
      document.write(myString2 + " has an invalid type of " + myString2.type);
    }

    document.close();

    -->

    </script>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» prototype