Page 161 - DCAP202_Fundamentals of Web Programming
P. 161

Fundamentals of Web Programming




                    Notes          2.  The ............................ object is useful when you want to display a date or use a timestamp in
                                       some sort of calculation.
                                   3.  A ............................. is a value or set of values (in the form of an array or object) that is a
                                       member of an object.
                                   4.  A ............................ is a function that is a member of an object.

                                   13.2 String Object


                                   The String object let’s you work with a series of characters and wraps Javascript’s string primitive
                                   data type with a number of helper methods.
                                   Because Javascript automatically converts between string primitives and String objects, you can
                                   call any of the helper methods of the String object on a string primitive.

                                   Syntax

                                   Creating a String object:
                                   The string parameter is series of characters that has been properly encoded.
                                   String Properties:

                                   Here is a list of each property and their description.
                                      Property                            Description
                                    constructor    Returns a reference to the String function that created the object.

                                    length       Returns the length of the string.
                                    prototype    The prototype property allows you to add properties and methods to an
                                                 object.





                                      Task  Illustrate the use of string object with example.

                                   13.2.1 Chaining Methods

                                   JavaScript provides all sorts of shortcut ways of specifying your code which makes the code
                                   quicker to write. One of these that relates to objects is the chaining together of two or more
                                   methods which need to be run on the same object. Instead of having to specify the object on the
                                   front of each method as we want to run it, we can chain all the methods together one after the
                                   other on the one object reference.


                                       !
                                     Caution  We just need to define the methods the right way in order to allow it.
                                     Let’s look at an example of this to see how it works. Here’s a section of the code where we
                                     define an object and then run several methods on the object.
                                     var  newB  =  new  example();
                                     newB.firstMethod(‘x’);
                                     newB.secondMethod(‘y’);
                                     newB.thirdMethod(1,15,’z’);


          154                               LOVELY PROFESSIONAL UNIVERSITY
   156   157   158   159   160   161   162   163   164   165   166